From 2d2a31779524eed3f32e234fe1323bd2b7402f49 Mon Sep 17 00:00:00 2001 From: seayu Date: Thu, 25 Aug 2022 13:00:53 +0800 Subject: [PATCH] fix:clone Object.create(null) --- func/clone.js | 2 +- test/base.test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/func/clone.js b/func/clone.js index 369df2c..3179281 100644 --- a/func/clone.js +++ b/func/clone.js @@ -16,7 +16,7 @@ function copyValue (val, isDeep) { if (val) { switch(objectToString.call(val)) { case "[object Object]": { - var restObj = Object.create(val.__proto__) + var restObj = Object.create(Object.getPrototypeOf(val)) objectEach(val, function (item, key) { restObj[key] = handleValueClone(item, isDeep) }) diff --git a/test/base.test.js b/test/base.test.js index 03087b3..482c48a 100644 --- a/test/base.test.js +++ b/test/base.test.js @@ -2492,6 +2492,9 @@ describe('Base functions', () => { expect( XEUtils.clone([['11', /\d/], [[11, [[new Date()], 22, [{ aa: 33 }, 44]]], { jj: 99 }], { uu: 88 }]) ).toEqual([['11', /\d/], [[11, [[new Date()], 22, [{ aa: 33 }, 44]]], { jj: 99 }], { uu: 88 }]) + expect( + XEUtils.clone(Object.create(null)) + ).toEqual(Object.create(null)) let v1 = { num: 11,