docs(clone): Fix docs for clone

This commit is contained in:
Sojin Park 2024-07-14 17:49:22 +09:00
parent dd267f9e79
commit f5b66fe650
3 changed files with 38 additions and 2 deletions

View File

@ -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
```

View File

@ -0,0 +1,36 @@
# clone
创建给定对象的浅拷贝。
## 签名
```typescript
function clone<T>(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
```

View File

@ -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);