Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

记一个将数组作为函数参数传递的小技巧 #3

Open
ibufu opened this issue Aug 31, 2016 · 0 comments
Open

记一个将数组作为函数参数传递的小技巧 #3

ibufu opened this issue Aug 31, 2016 · 0 comments

Comments

@ibufu
Copy link
Owner

ibufu commented Aug 31, 2016

const bar = [1, 2, 3];
foo(...bar);

等同于:

foo.apply(this, bar);

一个用例:

const middleware = [
    thunk,
    api,
    !__NODE__ && createLogger(),
].filter(Boolean);

export default function configureStore(initialState) {
    const store = createStore(
        rootReducer,
        initialState,
        compose(
            applyMiddleware(...middleware),
        )
    );

    return store;
}

redux 的 applyMiddleware 方法不能接受数组,可以利用这个方法方便地根据环境改变参数。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant