Javascript call() & apply() vs bind()?

后端 未结 22 2303
醉话见心
醉话见心 2020-11-22 02:42

I already know that apply and call are similar functions which setthis (context of a function).

The difference is with the way

22条回答
  •  梦如初夏
    2020-11-22 03:18

    Imagine, bind is not available. you can easily construct it as follow :

    var someFunction=...
    var objToBind=....
    
    var bindHelper =  function (someFunction, objToBind) {
        return function() {
            someFunction.apply( objToBind, arguments );
        };  
    }
    
    bindHelper(arguments);
    

提交回复
热议问题