Function: extend

extend<T, U>(to, from): T & U

将from所有的键值对都添加到to上面去,返回to

Type parameters

Name Type Description
T extends object 目标对象类型
U extends object 源对象类型

Parameters

Name Type Description
to T 目标对象
from U 源对象

Returns

T & U

合并后的对象

Example

const from = {mobile: '15858264903', nickname: 'liwb'};
const to = {nickname: 'cklwb'};

extend(to, from);
// => {nickname: "liwb", mobile: "15858264903"}

Example

const obj1 = {a: 1};
const obj2 = {b: 2};
extend(obj1, obj2);
// => {a: 1, b: 2}