-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ddfea3
commit 6743acf
Showing
1 changed file
with
13 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
export default function objectMergeDeep(base = {}, ...objs) { | ||
for (let i = 0, len = objs.length; i < len; ++i) { | ||
const obj = objs[i] | ||
const obj = objs[i]; | ||
|
||
for (const key in obj) { | ||
const value = obj[key] | ||
// see https://github.com/robinweser/fast-loops/issues/18 | ||
if (key === '__proto__' || key === 'constructor' || key === 'prototype') { | ||
continue; | ||
} | ||
|
||
const value = obj[key]; | ||
|
||
if (typeof value === 'object' && !Array.isArray(value)) { | ||
base[key] = objectMergeDeep(base[key], value) | ||
continue | ||
if (typeof value === 'object' && !Array.isArray(value) && value !== null) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
robinweser
Author
Owner
|
||
base[key] = objectMergeDeep(base[key], value); | ||
continue; | ||
} | ||
|
||
base[key] = value | ||
base[key] = value; | ||
} | ||
} | ||
|
||
return base | ||
} | ||
return base; | ||
} |
isn't this condition ambiguous?
is
value !== null
needed whentypeof value === 'object'
istrue
?