react.js - es6多个箭头函数
本文介绍了react.js - es6多个箭头函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
es6多个箭头函数看不太懂,例如下面这一段reddit=>dispatch=>...
这多重的箭头函数该怎么看
const fetchPosts = reddit => dispatch => {
dispatch(requestPosts(reddit))
return fetch(`https://www.reddit.com/r/${reddit}.json`)
.then(response => response.json())
.then(json => dispatch(receivePosts(reddit, json)))
}
解决方案
babeljs.io 在线转译
有不懂的,或者在学习过程中看不懂,希望去官方把ES6代码转译成你能认识的ES5代码。这样就一目了然了。
看看,这个转后的代码。你看得懂么?
"use strict";
var fetchPosts = function fetchPosts(reddit) {
return function (dispatch) {
dispatch(requestPosts(reddit));
return fetch("https://www.reddit.com/r/" + reddit + ".json").then(function (response) {
return response.json();
}).then(function (json) {
return dispatch(receivePosts(reddit, json));
});
};
};
这篇关于react.js - es6多个箭头函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文