Remove nativeBind usage#2199
Merged
Merged
Conversation
We cover almost all of nativeBind's cases: - Binding function to context - Binding function to context with args - Binding constructor with args The only downside is supported environments will no longer get the correct `length` property of the bound method. Usually, you subtract the number of bound args from `func`'s length. But, now Underscore is consistent between all environments.
Collaborator
|
I'm okay with this. edit: By the way, we can probably have additional performance gains (and avoid inconsistent behaviour between environments for sparse arrays that @jdalton always brings up) by removing the remaining native fallbacks. |
Closed
|
Alternative in #2198 which still uses native bind and therefore would preserve See: http://jsperf.com/underscore-js-2198-vs-2199 - #2198 was twice as fast as current, but this lodash-style approach blows it out of the water. |
Collaborator
|
This is a breaking for some constructor cases. Consider var D = _.bind(Date, null, 2015, 05)
new D(10);Sure this doesn't work in old environments but it may break some peoples code. It also affects other uses such as /cc @jdalton |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We cover almost all of nativeBind's cases:
The only downside is supported environments will no longer get the correct
lengthproperty of the bound method. Usually, you subtract the number of bound args fromfunc's length. But, now Underscore is consistent between all environments.http://jsperf.com/native-bind-vs-underscore/2
Re: #2197