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);
        };
    }
  • 相关阅读:
    php代码覆盖率执行
    如何更好的理解(pageX,pageY,clientX,clientY,eventX,eventY,scrollX,scrollY,screenX,screenY,event.offsetX,event.offsetY,offsetLeft,style.left)
    那些曾经纠结的大小写敏感
    jQuery中的经典动画
    月末总结
    小议jQuery中的事件
    DOM操作在jQuery中的实用------文字提示和图片提示
    HTML之表单元素
    http cookie
    HTML常用字符
  • 原文地址:https://www.cnblogs.com/nangezi/p/12346471.html
Copyright © 2011-2022 走看看