Object.assign()方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象。返回值为目标对象。
const obj = {
name: "zs",
age: 18,
sex: "man"
};
const newObj = Object.assign({ newname: "lisi" }, obj);
console.log(newObj, obj);
// { newname: ‘lisi‘, name: ‘zs‘, age: 18, sex: ‘man‘ } { name: ‘zs‘, age: 18, sex: ‘man‘ }
原文地址:https://www.cnblogs.com/bug-jin/p/10263909.html
时间: 2024-10-13 23:41:40