【发布时间】:2018-06-15 18:21:16
【问题描述】:
我一直在使用函数式 javascript,并且对使用解构的 util 函数有了一个想法。
是否可以使用...rest 传递对象键的名称以便稍后过滤掉属性?
通读 ...rest 文档,我没有看到任何关于解构的提及。
如果不能,有什么办法可以解决这个问题?
const stripObject = attr => ({ ...attr }) => ({ ...attr });
const getUserProps = stripObject(['_id', 'firstName']);
console.log(getUserProps({ _id: 1, firstName: 'foo', lastName: 'bar' }));
/*
I understand right now whats happening is the []
passed is being ignored and its just returning a
function that passing in all the props
{
_id: 1,
firstName: 'foo'
}
*/
【问题讨论】:
标签: javascript ecmascript-next