diff --git a/func/clone.js b/func/clone.js index 2db7f60..e6d9e15 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(val.__proto__ || null) objectEach(val, function (item, key) { restObj[key] = handleValueClone(item, isDeep) }) diff --git a/package.json b/package.json index 939b8c4..56def6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xe-utils", - "version": "3.5.20", + "version": "3.5.21", "description": "JavaScript 函数库、工具类", "main": "index.js", "unpkg": "dist/xe-utils.umd.min.js", diff --git a/test/base.test.js b/test/base.test.js index 03087b3..c915d54 100644 --- a/test/base.test.js +++ b/test/base.test.js @@ -2480,6 +2480,15 @@ describe('Base functions', () => { expect( XEUtils.clone(-1) ).toEqual(-1) + expect( + XEUtils.clone(Object.create(null)) + ).toEqual(Object.create(null)) + expect( + XEUtils.clone(Object.create({})) + ).toEqual(Object.create({})) + expect( + XEUtils.clone(Object.create([])) + ).toEqual(Object.create([])) expect( XEUtils.clone(/\n/) ).toEqual(/\n/)