了解嵌套箭头函数ES6

Vik*_*eni 6 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 })
)
Run Code Online (Sandbox Code Playgroud)

你能用多个箭头解释上面的功能吗?

Fal*_*aly 17

代码如下:

const logger = store => next => action => { return 'something'; }
Run Code Online (Sandbox Code Playgroud)

相当于:

const logger = function(store) { 
    return function(next) {
        return function(action) {
            return 'something';
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

它可以像下面这样调用:

var something = logger(store)(next)(action);
Run Code Online (Sandbox Code Playgroud)