es6中的雙箭頭函數


原代碼:

const fetchPosts = subreddit => dispatch => {

    dispatch(requestPosts(subreddit));

    return common.fetch({url: config.argumentSubmit, method: 'POST'})

    .then(response => response.message)

    .then(message => dispatch(receivePosts(subreddit, message)));

};

解析為:

const fetchPosts = function (subreddit) {

    return function (dispatch) {

            return  common.fetch({url: config.argumentSubmit, method: 'POST'})

                       .then(response => response.message)

                        .then(message => dispatch(receivePosts(subreddit, message)));
            }

}

雙箭頭意思是導出一個函數


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM