gpt4 book ai didi

javascript - 对象拆包赋值操作?

转载 作者:行者123 更新时间:2023-12-05 03:34:08 26 4
gpt4 key购买 nike

JavaScript 中有这样的东西吗?基本上,我正在寻找这些方面的东西:

let obj_a = {test: "one", property: "two"};
let obj_b = {test: "1", other: "three"};
let obj_b ...= obj_a; // would be the equivalent of obj_b = {...obj_b, ...obj_a}

是否有类似的内置语法,或者这是我将在 ES6 中获得的最佳语法?

最佳答案

Object.assign会做。

let obj_a = { test: "one", property: "two" },
obj_b = { test: "1", other: "three" };

Object.assign(obj_b, obj_a);

console.log(obj_b);

关于javascript - 对象拆包赋值操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70219827/

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