Skip to content
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

Aliases should be to .call #13

Closed
jdunck opened this issue Feb 5, 2010 · 3 comments
Closed

Aliases should be to .call #13

jdunck opened this issue Feb 5, 2010 · 3 comments
Labels

Comments

@jdunck
Copy link

jdunck commented Feb 5, 2010

You have a bunch of aliases of the form:
var slice = Array.prototype.slice

In most, if not all, cases, you then use that as slice.call.

If it's truly done for performance, your aliases should be to
var slicecall = Array.prototype.slice.call

That'll save one more attr lookup in a ton of loops.

@documentcloud
Copy link

That's a nice thought, but I'm afraid that pulling off a reference to Function#call isn't going to get you the original method -- it's just going to get you a broken version of call.

slice = Array.prototype.slice ;
sliceCall = Array.prototype.slice.call;

slice.call([1, 2, 3, 4, 5], 2)
=> [3, 4, 5]

sliceCall([1, 2, 3, 4, 5], 2)
=> TypeError: Type error

Closing the ticket.

@jdunck
Copy link
Author

jdunck commented Feb 5, 2010

Well, I was thinking
sliceCall = _.bind(slice.call, slice)
but I guess that doesn't save anything since .apply still has to be run in the func returned by .bind. :-/

@documentcloud
Copy link

Sure, but an extra function invocation is slower than a property access in any case:

Benchmark

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant