Giter Site home page Giter Site logo

Comments (16)

arian avatar arian commented on July 22, 2024

This seems to pass the @jdalton test: http://jsfiddle.net/QF9ZA/2/

from mootools-core.

cpojer avatar cpojer commented on July 22, 2024

Note that there are three different cases:

1.3 without native bind: fix this one
1.3 with native bind: √
1.2compat: ignore this

from mootools-core.

arian avatar arian commented on July 22, 2024

This should fix 1.3 without compat or native bind: arian@5c1df58c0d0

from mootools-core.

arian avatar arian commented on July 22, 2024

In new browsers this changes slows down bind significantly. In IE8 (about 10%) and 7 the difference is less, but still slower (of course) http://jsperf.com/function-proto-bind

from mootools-core.

jdalton avatar jdalton commented on July 22, 2024

I think there is probably room to tweak a bit, but the speed diff doesn't concern me much. Doing things right could come at a cost and it makes sense now that native is faster than the updated fallback.

from mootools-core.

ibolmo avatar ibolmo commented on July 22, 2024

Agreed, and thanks to Arian's clarification 1.3 runs native if present and for 1.2 with compat runs a much slower version :(. Nevertheless, I guess the bench should compare against non native bind. Finally, agreed that there's only too much one can do to speed this up.

from mootools-core.

cpojer avatar cpojer commented on July 22, 2024

I'm cool with this. We should only fix 1.3 (1.2compat is non-standard anyway) and only few browsers don't have bind natively, so we should be fine :) Pull Request !

from mootools-core.

cpojer avatar cpojer commented on July 22, 2024

Oh man, Safari still doesn't have bind :o

from mootools-core.

cpojer avatar cpojer commented on July 22, 2024

Also, we can probably use

(this && this != window)

as an adequate check.

@jdalton - what do you think?

from mootools-core.

seanmonstar avatar seanmonstar commented on July 22, 2024

a check for this != window means it breaks in a headless environment.

from mootools-core.

arian avatar arian commented on July 22, 2024

What about arian@b38e69f886

from mootools-core.

jdalton avatar jdalton commented on July 22, 2024

@cpojer this could be none-window a lot of the time so that wouldn't do:

For example:

foo.bar = baz.bar.bind(baz, 'x', 'y');

Also ya'll could take it up a notch and implement a custom call/apply method too (I'll update my list to include that). By spec bound.call(thisArg, 'z') should ignore thisArg and curry args as if called like bound('z').

from mootools-core.

arian avatar arian commented on July 22, 2024

@jdalton: that should already work: http://jsfiddle.net/arian/QF9ZA/6/

var other = function(){
    console.log(this.foo, arguments);
};
other.bind({foo: 'bar'})(); // → bar
other.bind({foo: 'bar'}, 'first').call({foo: 'yeah!'}, 'yooo'); // → bar, ['first', 'yeah!']

from mootools-core.

jdalton avatar jdalton commented on July 22, 2024

@arian except if you call/apply with an instance of the bound function as the thisArg. It shouldn't be treated as new bound.

from mootools-core.

arian avatar arian commented on July 22, 2024

So am I missing something? https://gist.github.com/1124879

from mootools-core.

jdalton avatar jdalton commented on July 22, 2024

@arian add a test for .apply() too

from mootools-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.