Lev*_*Lev 2 javascript ecmascript-6
给出以下示例.是否有现场指定的简写
let myObj = {someField: 'someValue'}
let foo = 'value'
myObj.foo = foo // I would like to do the opposite of object destructuring: const {foo} = myObj. I don't want to repeat foo twice.
Run Code Online (Sandbox Code Playgroud)
你可以使用Object.assign
一个短手属性.
const myObj = {}
const foo = 'value'
Object.assign(myObj, { foo });
console.log(myObj);
Run Code Online (Sandbox Code Playgroud)