-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix util extend issue #2334
Fix util extend issue #2334
Conversation
When the "origin" object argument is null or not defined, _extend throws exception. Fix _extend to allow undefined "origin" object argument and return the "add" object argument.
Should we not be returning a copy of add? (ie: set Imho, we should always return |
Fix _extend to allow undefined "origin" object argument and create a new origin object to return, instead of returning "add" object argument.
I totally agree @ronkorving. I've just pushed a fix for this suggested behavior, so the |
Thanks! 👍 |
Is the use case for this just cloning an object, or am I missing something? |
@@ -715,6 +715,9 @@ exports._extend = function(origin, add) { | |||
// Don't do anything if add isn't an object | |||
if (add === null || typeof add !== 'object') return origin; | |||
|
|||
// Create new object for origin, if origin isn't an object | |||
if (origin === null || typeof origin !== 'object') origin = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that the above condition uses || typeof add !== 'object'
, but I'd rather not see that added again down below. util._extend(36, {a: 42})
makes no sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @brendanashworth. util._extend(36, {a: 42})
is nonsensical and should probably blow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
I'm not sure that this is really pressing enough to be added. |
-1 on this. Not seeing the benefit (extending a null or undefined should blow up IMO). given the lack of activity, closing. Can reopen if anyone feel it is necessary. |
FWIW, we also have |
Object.assign is quite slow unfortunately :( |
When the "origin" object argument is null or not defined, _extend
throws exception.
Fix _extend to allow undefined "origin" object argument and return
the "add" object argument.