Object.assign()用法讲解
小开开 2021-04-08 15:02:47 2021-04-08 208 0
语法: Object.assign(target, …sources) target: 目标对象,sources: 源对象
用于将所有可枚举属性的值从一个或多个源对象复制到目标对象。它将返回目标对象。
const source = { b: 4, c: 5 };const returnedTarget = Object.assign(target, source);console.log(target); // Object { a: 1, b: 4, c: 5 }console.log(returnedTarget); // Object { a: 1, b: 4, c: 5 }