有没有办法动态获取函数的函数参数名称?
假设我的函数看起来像这样:
function doSomething(param1, param2, .... paramN){
// fill an array with the parameter name and value
// some other code
}
Run Code Online (Sandbox Code Playgroud)
现在,我如何从函数内部获取参数名称及其值的列表到数组中?
我只是制作一个简单的应用程序来学习与redux的异步.我已经完成了所有工作,现在我只想在网页上显示实际状态.现在,我如何在render方法中实际访问商店的状态?
这是我的代码(一切都在一页,因为我只是在学习):
const initialState = {
fetching: false,
fetched: false,
items: [],
error: null
}
const reducer = (state=initialState, action) => {
switch (action.type) {
case "REQUEST_PENDING": {
return {...state, fetching: true};
}
case "REQUEST_FULFILLED": {
return {
...state,
fetching: false,
fetched: true,
items: action.payload
}
}
case "REQUEST_REJECTED": {
return {...state, fetching: false, error: action.payload}
}
default:
return state;
}
};
const middleware = applyMiddleware(promise(), thunk, logger());
const store = createStore(reducer, middleware);
store.dispatch({
type: "REQUEST",
payload: fetch('http://localhost:8000/list').then((res)=>res.json())
});
store.dispatch({ …Run Code Online (Sandbox Code Playgroud) subscribe在代码中使用的目的是什么store.subscribe(render)?每次商店的状态发生变化时,是否使用mapStateToProps并且connect已经导致连接的组件重新渲染?