Object.assign( )

将所有可枚举属性的值从 source 对象复制到 target 对象。它将返回 target 对象。

const target = { a:1, b:2 };
const source = { b:10, c:20 };
const returnTarget = Object.assign( target, source );
console.log( target );          //输出:{ a: 1, b: 10, c: 20 }
console.log( returnTarget );    //输出:{ a: 1, b: 10, c: 20 }

猜你喜欢

转载自www.cnblogs.com/xiaoxuStudy/p/12723884.html