From a6d708e53ff55aafd289d6508fadb12141afed1a Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:59:16 -0400 Subject: [PATCH] refactor!: make `clone` more strict --- src/object/clone.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/object/clone.ts b/src/object/clone.ts index eb7f2ea0..3d09bdc2 100644 --- a/src/object/clone.ts +++ b/src/object/clone.ts @@ -1,21 +1,9 @@ -import { isPrimitive } from 'radashi' - /** * Creates a shallow copy of the given obejct/value. * @param {*} obj value to clone @returns {*} shallow clone of the * given value */ -export function clone(obj: T): T { - // Primitive values do not need cloning. - if (isPrimitive(obj)) { - return obj - } - - // Binding a function to an empty object creates a copy function. - if (typeof obj === 'function') { - return obj.bind({}) - } - +export function clone(obj: T): T { const proto = Object.getPrototypeOf(obj) const newObj = typeof proto?.constructor === 'function'