Avoiding .call() and .apply() using .bind()

后端 未结 2 1072
时光取名叫无心
时光取名叫无心 2021-02-05 13:24

I\'m looking for a way to accomplish a certain task and that is, going from

jQuery.when.apply( null, promiseArray ).done(...)

to



        
相关标签:
2条回答
  • 2021-02-05 13:45

    bind accepts a variable number of arguments, so you can partially apply a method. So, instead of:

    var when = Function.prototype.apply.bind( $.when );
    

    Do this:

    var when = Function.prototype.apply.bind( $.when , null );
    

    And updated jsfiddle: http://jsfiddle.net/pp26L/2/

    0 讨论(0)
  • 2021-02-05 13:56

    This should work:

    when = Function.prototype.apply.bind( $.when, null);
    

    You just bind (or curry, if you prefer) the first argument of .bind and fix it to null.

    Fiddle.

    0 讨论(0)
提交回复
热议问题