Skip to content

Commit

Permalink
Merge pull request #45 from sea-yu/fix/clone
Browse files Browse the repository at this point in the history
fix:clone Object.create(null)
  • Loading branch information
xuliangzhan authored Mar 5, 2024
2 parents 00199f3 + af939a1 commit 19792b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion func/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function copyValue (val, isDeep) {
if (val) {
switch(objectToString.call(val)) {
case "[object Object]": {
var restObj = Object.create(val.__proto__ || null)
var restObj = Object.create(Object.getPrototypeOf(val))
objectEach(val, function (item, key) {
restObj[key] = handleValueClone(item, isDeep)
})
Expand Down
3 changes: 3 additions & 0 deletions test/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,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,
Expand Down

0 comments on commit 19792b5

Please sign in to comment.