Skip to content

Commit

Permalink
fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
robinweser committed Jul 4, 2024
1 parent 4ddfea3 commit 6743acf
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions modules/objectMergeDeep.js
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.

Copy link
@aaleksu

aaleksu Jul 11, 2024

isn't this condition ambiguous?
is value !== null needed when typeof value === 'object' is true?

This comment has been minimized.

Copy link
@robinweser

robinweser Jul 11, 2024

Author Owner

Yeah, you're right. We can remove that. Took it from another implementation and haven't thought about it too much.

This comment has been minimized.

Copy link
@aaleksu

aaleksu Jul 11, 2024

actually, it might be even dangerous to leave it as it is because null is valid value.
if it was a key, then maybe it would make sense.

base[key] = objectMergeDeep(base[key], value);
continue;
}

base[key] = value
base[key] = value;
}
}

return base
}
return base;
}

0 comments on commit 6743acf

Please sign in to comment.