Skip to content

对象方法 ​

2023-03-24 20:37:15

assign ​

将所有可枚举的自有属性从一个或多个源对象复制到目标对象,返回修改后的对象

ts
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };

const returnedTarget = Object.assign(target, source);

console.log(target);
// Expected output: Object { a: 1, b: 4, c: 5 }

console.log(returnedTarget === target);
// Expected output: true

Released under the MIT License.