<分区>
所以我想弄清楚是否有任何简单的 ES6 语法可以执行以下操作:
如果我有对象
const config = { foo: null, bar: null }
我想从另一个对象分配这些属性的值,例如:
const source = { hello: "hello", world: "world", another: "lorem", onemore: "ipsum" }
我想做类似下面的事情,但它不起作用
{ hello:config.foo, world:config.bar } = source
我知道我可以做一些非常接近的事情,比如:
{ hello:foo, world:bar } = source
但这会创建新变量 foo
和 bar
,而我想分配给另一个对象的现有属性。我很好奇是否有 ES6 的简写形式;使用传统代码我不需要帮助,我知道有很多方法,而且我已经知道其中的大部分。