diff --git a/docs/reference/object/clone.md b/docs/reference/object/clone.md index bbe51959..39f24726 100644 --- a/docs/reference/object/clone.md +++ b/docs/reference/object/clone.md @@ -31,6 +31,6 @@ console.log(clonedArr === arr); // false const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] }; const clonedObj = clone(obj); -console.log(clonedObj); // { a: 1, b: 'es-toolkit' } +console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] } console.log(clonedObj === obj); // false ``` diff --git a/docs/zh_hans/reference/object/clone.md b/docs/zh_hans/reference/object/clone.md new file mode 100644 index 00000000..2d844ab8 --- /dev/null +++ b/docs/zh_hans/reference/object/clone.md @@ -0,0 +1,36 @@ +# clone + +创建给定对象的浅拷贝。 + +## 签名 + +```typescript +function clone(value: T): T; +``` + +### 参数 + +- `obj` (`T`): 要克隆的对象。 + +### 返回 + +(`T`): 给定对象的浅拷贝 + +## 示例 + +```typescript +const num = 29; +const clonedNum = clone(num); +console.log(clonedNum); // 29 +console.log(clonedNum === num); // true + +const arr = [1, 2, 3]; +const clonedArr = clone(arr); +console.log(clonedArr); // [1, 2, 3] +console.log(clonedArr === arr); // false + +const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] }; +const clonedObj = clone(obj); +console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] } +console.log(clonedObj === obj); // false +``` diff --git a/src/object/clone.spec.ts b/src/object/clone.spec.ts index 91e60320..4af6a7fe 100644 --- a/src/object/clone.spec.ts +++ b/src/object/clone.spec.ts @@ -22,7 +22,7 @@ describe("clone", () => { }); it("should clone objects", () => { - const obj = { a: 1, b: "es-toolkit" }; + const obj = { a: 1, b: "es-toolkit", c: [1, 2, 3] }; const clonedObj = clone(obj); expect(clonedObj).toEqual(obj);