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

后端 未结 2 1196
时光取名叫无心
时光取名叫无心 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/

提交回复
热议问题