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

Possible improvement? #26

Closed
cowboy opened this issue Jun 8, 2012 · 2 comments
Closed

Possible improvement? #26

cowboy opened this issue Jun 8, 2012 · 2 comments
Labels

Comments

@cowboy
Copy link

cowboy commented Jun 8, 2012

Before:

// Up front
var toString = Object.prototype.toString;

// 21 times thereafter
toString.call(value)

After:

// Up front
var toString = _.bind(Function.call, Object.prototype.toString);

// 21 times thereafter
toString(value)

For all the things?

/** Native prototype shortcuts */
var ArrayProto = Array.prototype,
    ObjectProto = Object.prototype,
    FunctionCall = Function.call,
    FunctionApply = Function.apply;

/** Native method shortcuts */
var concat = _.bind(FunctionApply, ArrayProto.concat),
    hasOwnProperty = _.bind(FunctionCall, ObjectProto.hasOwnProperty),
    push = _.bind(FunctionApply, ArrayProto.push),
    slice = _.bind(FunctionCall, ArrayProto.slice),
    toString = _.bind(FunctionCall, ObjectProto.toString);

Anyways... just a thought.

@jdalton
Copy link
Member

jdalton commented Jun 8, 2012

@cowboy Thanks, I've seen this pattern used before and it is hawt. But I dig reducing function calls and dependencies and this would would make bind pretty much a hard dependency and add function calls/complexity when the _.bind fallback is used. In the end it's probably all gzipped away anyways.

@jdalton jdalton closed this as completed Jun 8, 2012
@jdalton jdalton added the wontfix label Jun 3, 2014
@lock
Copy link

lock bot commented Jan 21, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants