Function: deepClone

deepClone<T>(obj): T

深层克隆对象

Type parameters

Name
T

Parameters

Name Type Description
obj T 要克隆的对象

Returns

T

  • 克隆后的新对象

Example

const a = { foo: 'bar', obj: { a: 1, b: 2 } };
const b = deepClone(a);
// => a !== b, a.obj !== b.obj

Example

const arr = [1, 2, { a: 3 }];
const clonedArr = deepClone(arr);
// => arr !== clonedArr, arr[2] !== clonedArr[2]