首页 > Web开发 > 详细

js 多个箭头函数的使用

时间:2020-04-01 00:02:20      阅读:272      评论:0      收藏:0      [点我收藏+]

 

多个箭头函数,例如:

const navigateOnce = (getStateForAction) => (action, state) => {
    const {type, routeName, params} = action;
    return (
        state &&
        (type === NavigationActions.NAVIGATE) &&
        routeName === state.routes[state.routes.length - 1].routeName &&
        JSON.stringify(params) === JSON.stringify(state.routes[state.routes.length - 1].params)
    ) ? null getStateForAction(action, state);
};

 

箭头函数的含义:

() => ...
//等价于
(function() {
    return ...
}).bind(this)

 

注意: 箭头函数在不写{} 的情况下,可以省略return关键字,而默认return接下来的东西

由此可见:类似

() => () => ...

等价于:

() => {return () => {return ...}}

等价于

function () {
    retunrn function() {
        return ...
    }
}

 

综上,上面函数的意思就是:

const navigateOnce = function(getStateForAction) {
    return (action, state) => {
        const {type, routeName, params} = action;
        return (
            state &&
            (type === NavigationActions.NAVIGATE) &&
            routeName === state.routes[state.routes.length - 1].routeName &&
            JSON.stringify(params) === JSON.stringify(state.routes[state.routes.length - 1].params)
        ) ? null getStateForAction(action, state);
    };
}

即:

const navigateOnce = function(getStateForAction) {
    return function(action, state) {
        const {type, routeName, params} = action;
        return (
            state &&
            (type === NavigationActions.NAVIGATE) &&
            routeName === state.routes[state.routes.length - 1].routeName &&
            JSON.stringify(params) === JSON.stringify(state.routes[state.routes.length - 1].params)
        ) ? null getStateForAction(action, state);
    };
}

 

js 多个箭头函数的使用

原文:https://www.cnblogs.com/nangezi/p/12346471.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!