What is the difference between $.proxy() and bind()?

前端 未结 5 1576
暖寄归人
暖寄归人 2021-02-03 22:43

In 2009, ECMAScript 5 added a built-in bind() function which takes an object as a parameter and returns an identical function in which this will always

5条回答
  •  我寻月下人不归
    2021-02-03 23:01

    $.proxy came first. Below is a simple way to preserve a particular context on function call

    var myProxy = (function(context,fn){
      return function(){
          fn.call(context);
      }
    })( myContext, myFn );
    

    You could easily use this before it came out jquery.

    Answer is simple: bind is the official. Use bind - if it really is supported in browsers which is required to run the script

提交回复
热议问题