gpt4 book ai didi

javascript - 增强对象字面量中的对象解构

转载 作者:行者123 更新时间:2023-12-01 01:03:16 25 4
gpt4 key购买 nike

ES6 有没有办法在一行或更短的时间内执行以下操作?

const { bar } = this.foo;
this.module.func({
bar,
});

我尝试的是以下内容,但不起作用,并且是语法错误。

const { bar } = this.foo;
this.module.func({
{ bar }: this.foo, // unexpected token
});

最佳答案

除非重复属性名称,否则不能将其作为单行代码执行:

this.module.func({ 
bar: this.foo.bar
});

关于javascript - 增强对象字面量中的对象解构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55865113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com