Object.assign( )

Posted xiaoxustudy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }

 

以上是关于Object.assign( )的主要内容,如果未能解决你的问题,请参考以下文章