-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Fixes #1739 - _.extend check for own properties #1770
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
Conversation
@@ -912,11 +912,13 @@ | |||
// Extend a given object with all the properties in passed-in object(s). | |||
_.extend = function(obj) { | |||
if (!_.isObject(obj)) return obj; | |||
var source, prop; | |||
var source, prop, hasOwn = Object.prototype.hasOwnProperty; |
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.
This is already defined as hasOwnProperty
.
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.
Yes, good point. I missed line 26 in the quick reference variables:
var hasOwnProperty = ObjProto.hasOwnProperty;
I'll push a squashed commit.
That's correct. |
|
I agree with @jdalton. |
Fixes #1739 - _.extend check for own properties
👍 |
In retrospect, I think it was a mistake to change this behavior. It was unnecessarily backwards-incompatible, and not obviously more useful. If you're using it on naked objects then the behavior is identical ... but if you're using it on inherited objects then you're getting only a subset of what you were getting previously. I think that "any iterable property" is a nicer default for such a brute-force function. So, reverting for 1.7.1... |
Reverting this has side effects on other methods like Devs using |
I agree with that. But let's push back on this breaking change til later. Let's back it out to the old behavior for now. |
Yap, for 1.7.1 it makes sense to back it out as it's back compat breaking. |
I believe _.extend is intended to remain primitive in nature (as per issue #123), so this may be an unnecessary change.
Checks for the source object's own properties before extending a property. It includes the code from Dimik's comment resolving issue #1739. One contributed test; All tests pass.
Screenshots highlight lines of code added to underscore.js and object tests:



underscore.js:
test/objects.js:
Passing tests: