mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 20:26:33 +03:00
128147b108
* feat: add clone(shallow copy) implementaion and test codes * chore: add benchamark of clone * docs: add docs of clone * chore: bench number * Update docs/ko/reference/object/clone.md --------- Co-authored-by: Sojin Park <raon0211@toss.im>
724 B
724 B
clone
주어진 객체의 얇은 복사본을 생성해요.
Signature
function clone<T>(value: T): T;
Parameters
obj
(T
): 복사할 객체예요.
Returns
(T
): 주어진 객체의 얇은 복사본이에요.
Examples
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