了解嵌套箭头函数ES6

时间:2018-01-31 11:09:29

标签: javascript ecmascript-6

const logger = store => next => action => {
    let result
    console.groupCollapsed("dispatching", action.type)
    console.log('prev state', store.getState())
    console.log('action', action)
    result = next(action)
    console.log('next state', store.getState())
    console.groupEnd()
    return result
}

const store = applyMiddleware(logger)(createStore)(
    combineReducers({ colors, sort })
)

请您用多个箭头解释上述功能吗?

1 个答案:

答案 0 :(得分:15)

以下代码:

const logger = store => next => action => { return 'something'; }

相当于:

const logger = function(store) { 
    return function(next) {
        return function(action) {
            return 'something';
        }
    }
}

可以像下面这样调用:

var something = logger(store)(next)(action);