根据ES2017 规范,message的属性是Error不可枚举的。我想知道为什么会这样?对于不可枚举的属性,message不可能像Error这样传播对象
const payload = new Error('oops!');
// Few lines after
const nextState = {
...payload
};
Run Code Online (Sandbox Code Playgroud)
这在使用 Redux 和 SFA(标准通量操作)时特别有用。SFA 允许操作的有效负载是一个Error对象。这样的动作可以由像这样的减速器处理
// e.g. with redux-actions library
// that provides `handleActions` helper
export default handleActions({
[ERROR_ACTION]: (state, ({ payload }) => ({ ...state, ...payload })
}, initialState)
Run Code Online (Sandbox Code Playgroud)
但由于 的message属性Error是不可枚举的,上面代码中的有效负载不会被传播。
有人对此有好的答案吗?