zoukankan      html  css  js  c++  java
  • js 多个箭头函数的使用

    多个箭头函数,例如:

    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);
        };
    }
  • 相关阅读:
    hdu 3613 Best Reward 扩展kmp
    hdu 4333 Revolving Digits 扩展kmp
    poj 1904 King's Quest 强连通
    hdu 3068 最长回文 manacher
    Codeforces Round #243 (Div. 2) C. Sereja and Swaps
    poj 3680 Intervals 费用流
    两个kmp hdu 2594 & hdu 2087
    hdu 3336 count the string
    Arcgis安装要素
    JS关闭窗口而不提示
  • 原文地址:https://www.cnblogs.com/nangezi/p/12346471.html
Copyright © 2011-2022 走看看