-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Make options object prototype-inherited #2300
Conversation
if (props.options && proto.options) { | ||
props.options = L.extend({}, proto.options, props.options); | ||
if (proto.options) { | ||
props.options = L.Util.extend(L.Util.create(proto.options), props.options); |
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.
we could also reuse L.Util.create
above for proto creation, right?
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.
Yep, f2b34cd
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.
Beautiful.
This is awesome, thanks a lot for taking on this! |
BTW, did you look how it affects performance? Like, measure instantiating 100000 markers with some options? |
Also, I guess accessing properties that got inherited will become a bit slower because of prototype chain lookup, but it would be insignificant in theory. |
expect(o.options).not.to.equal(opts); | ||
}); | ||
|
||
it("doesn't create a distinct options object if object already has own options", function () { |
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.
Is there a real use case for this? Not doing the hasOwnProperty check makes it a little faster.
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 was thinking that if L.Util.setOptions
was called multiple times on the same object you wouldn't want it to add another link in the prototype chain each time.
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.
Oh, yeah that makes sense! So all the setStyle
stuff would be affected, etc.
No, I didn't do any performance testing. |
Make options object prototype-inherited
Fixes #2294