我已经知道apply并且call是设置this(函数的上下文)的类似函数。
不同之处在于我们发送参数的方式(手动与数组)
问题:
但是我什么时候应该使用该  bind()方法?
var obj = {
  x: 81,
  getX: function() {
    return this.x;
  }
};
alert(obj.getX.bind(obj)());
alert(obj.getX.call(obj));
alert(obj.getX.apply(obj));
    我已经知道apply并且call是设置this(函数的上下文)的类似函数。
不同之处在于我们发送参数的方式(手动与数组)
问题:
但是我什么时候应该使用该  bind()方法?
var obj = {
  x: 81,
  getX: function() {
    return this.x;
  }
};
alert(obj.getX.bind(obj)());
alert(obj.getX.call(obj));
alert(obj.getX.apply(obj));
    .bind()当您希望稍后在特定上下文中调用该函数时使用,这在事件中很有用。当您想立即调用函数并修改上下文时使用.call()或。.apply()
Call/apply 立即调用该函数,而bind返回一个函数,该函数在稍后执行时将具有正确的上下文集以调用原始函数。这样您就可以在异步回调和事件中维护上下文。
我经常这样做:
function MyObject(element) {
    this.elm = element;
    element.addEventListener('click', this.onClick.bind(this), false);
};
MyObject.prototype.onClick = function(e) {
     var t=this;  //do something with [t]...
    //without bind the context of this function wouldn't be a MyObject
    //instance as you would normally expect.
};
我在 Node.js 中将它广泛用于异步回调,我想为其传递一个成员方法,但仍希望上下文是启动异步操作的实例。
一个简单、朴素的 bind 实现如下:
Function.prototype.bind = function(ctx) {
    var fn = this;
    return function() {
        fn.apply(ctx, arguments);
    };
};
它还有更多内容(例如传递其他参数),但您可以阅读有关它的更多信息并查看MDN 上的实际实现。
它们都将它附加到函数(或对象)中,不同之处在于函数调用(见下文)。
call将此附加到函数中并立即执行该函数:
var person = {  
  name: "James Smith",
  hello: function(thing) {
    console.log(this.name + " says hello " + thing);
  }
}
person.hello("world");  // output: "James Smith says hello world"
person.hello.call({ name: "Jim Smith" }, "world"); // output: "Jim Smith says hello world"
bind将此附加到函数中,并且需要像这样单独调用它:
var person = {  
  name: "James Smith",
  hello: function(thing) {
    console.log(this.name + " says hello " + thing);
  }
}
person.hello("world");  // output: "James Smith says hello world"
var helloFunc = person.hello.bind({ name: "Jim Smith" });
helloFunc("world");  // output: Jim Smith says hello world"
或像这样:
...    
var helloFunc = person.hello.bind({ name: "Jim Smith" }, "world");
helloFunc();  // output: Jim Smith says hello world"
apply与call类似,只是它接受一个类似数组的对象,而不是一次列出一个参数:
function personContainer() {
  var person = {  
     name: "James Smith",
     hello: function() {
       console.log(this.name + " says hello " + arguments[1]);
     }
  }
  person.hello.apply(person, arguments);
}
personContainer("world", "mars"); // output: "James Smith says hello mars", note: arguments[0] = "world" , arguments[1] = "mars"                                     
    以最简单的形式回答
称呼
var person1 = {firstName: 'Jon', lastName: 'Kuperman'};
var person2 = {firstName: 'Kelly', lastName: 'King'};
function say(greeting) {
    console.log(greeting + ' ' + this.firstName + ' ' + this.lastName);
}
say.call(person1, 'Hello'); // Hello Jon Kuperman
say.call(person2, 'Hello'); // Hello Kelly King
申请
var person1 = {firstName: 'Jon', lastName: 'Kuperman'};
var person2 = {firstName: 'Kelly', lastName: 'King'};
function say(greeting) {
    console.log(greeting + ' ' + this.firstName + ' ' + this.lastName);
}
say.apply(person1, ['Hello']); // Hello Jon Kuperman
say.apply(person2, ['Hello']); // Hello Kelly King
绑定
var person1 = {firstName: 'Jon', lastName: 'Kuperman'};
var person2 = {firstName: 'Kelly', lastName: 'King'};
function say() {
    console.log('Hello ' + this.firstName + ' ' + this.lastName);
}
var sayHelloJon = say.bind(person1);
var sayHelloKelly = say.bind(person2);
sayHelloJon(); // Hello Jon Kuperman
sayHelloKelly(); // Hello Kelly King
呼叫和申请是可以互换的。只需决定是否更容易发送数组或逗号分隔的参数列表。
我总是通过记住 Call 用于逗号(分隔列表)而 Apply 用于 Array 来记住哪个是哪个。
绑定有点不同。它返回一个新函数。Call 和 Apply 立即执行当前函数。
Bind 适用于很多事情。我们可以使用它来像上面的例子一样对函数进行柯里化。我们可以使用一个简单的 hello 函数并将其转换为 helloJon 或 helloKelly。我们还可以将它用于诸如 onClick 之类的事件,我们不知道它们何时会被触发,但我们知道我们希望它们具有什么上下文。
TL;博士:
简单来说,bind 创建函数,调用和应用执行函数,而 apply 需要数组中的参数
完整说明
假设我们有multiplication函数
function multiplication(a,b){
console.log(a*b);
}
让我们使用创建一些标准函数bind
var multiby2 = multiplication.bind(this,2);
现在 multiby2(b) 等于 multiplication(2,b);
multiby2(3); //6
multiby2(4); //8
如果我在绑定中传递两个参数怎么办
var getSixAlways = multiplication.bind(this,3,2);
现在 getSixAlways() 等于乘法(3,2);
getSixAlways();//6
即使传递参数返回6;
getSixAlways(12); //6
var magicMultiplication = multiplication.bind(this);
这将创建一个新的乘法函数并将其分配给 magicMultiplication。
哦,不,我们将乘法功能隐藏在 magicMultiplication 中。
调用
magicMultiplication返回一个空白function b()
在执行时它工作正常
magicMultiplication(6,5); //30
打电话申请怎么样?
magicMultiplication.call(this,3,2); //6
magicMultiplication.apply(this,[5,2]); //10
它允许设置与this函数调用方式无关的值。这在处理回调时非常有用:
  function sayHello(){
    alert(this.message);
  }
  var obj = {
     message : "hello"
  };
  setTimeout(sayHello.bind(obj), 1000);
要达到相同的结果,call如下所示:
  function sayHello(){
    alert(this.message);
  }
  var obj = {
     message : "hello"
  };
  setTimeout(function(){sayHello.call(obj)}, 1000);
    两者都Function.prototype.call()调用Function.prototype.apply()具有给定this值的函数,并返回该函数的返回值。
Function.prototype.bind()另一方面,创建一个具有给定this值的新函数,并返回该函数而不执行它。
因此,让我们使用如下所示的函数:
var logProp = function(prop) {
    console.log(this[prop]);
};
现在,让我们看一个如下所示的对象:
var Obj = {
    x : 5,
    y : 10
};
我们可以像这样将我们的函数绑定到我们的对象:
Obj.log = logProp.bind(Obj);
现在,我们可以Obj.log在代码中的任何地方运行:
Obj.log('x'); // Output : 5
Obj.log('y'); // Output : 10
真正有趣的地方在于,您不仅绑定了 for 的值this,还绑定了 for 的参数prop:
Obj.logX = logProp.bind(Obj, 'x');
Obj.logY = logProp.bind(Obj, 'y');
我们现在可以这样做:
Obj.logX(); // Output : 5
Obj.logY(); // Output : 10
    所有这些方法背后的主要概念是Function burrowing。
函数借用允许我们在不同对象上使用一个对象的方法,而无需复制该方法并将其保存在两个不同的地方。它是通过使用 . 称呼() , 。应用(),或。bind() ,所有这些都是为了在我们借用的方法上显式设置 this
以下是所有这些方法的示例
let name =  {
    firstname : "Arham",
    lastname : "Chowdhury",
}
printFullName =  function(hometown,company){
    console.log(this.firstname + " " + this.lastname +", " + hometown + ", " + company)
}
称呼
调用方法中的第一个参数,例如 name 始终是对 (this) 变量的引用,后者将是函数变量
printFullName.call(name,"Mumbai","Taufa");     //Arham Chowdhury, Mumbai, Taufa
申请
apply 方法与 call 方法相同,唯一的区别是,函数参数在数组列表中传递
printFullName.apply(name, ["Mumbai","Taufa"]);     //Arham Chowdhury, Mumbai, Taufa
绑定
bind 方法与 call 相同,只是 bind 返回一个函数,稍后可以通过调用它来使用它(不会立即调用它)
let printMyNAme = printFullName.bind(name,"Mumbai","Taufa");
printMyNAme();      //Arham Chowdhury, Mumbai, Taufa
printMyNAme() 是调用函数的函数
下面是 jsfiddle 的链接
bind:它将函数与提供的值和上下文绑定,但不执行函数。要执行函数,您需要调用该函数。
call:它使用提供的上下文和参数执行函数。
apply:它使用提供的上下文和 参数作为数组执行函数。
这是一篇很好的文章来说明 和 之间的区别,bind()总结如下。apply()call()
bind()允许我们轻松设置调用函数或方法时将绑定到this的特定对象。
// This data variable is a global variable
var data = [
    {name:"Samantha", age:12},
    {name:"Alexis", age:14}
]
var user = {
    // local data variable
    data    :[
        {name:"T. Woods", age:37},
        {name:"P. Mickelson", age:43}
    ],
    showData:function (event) {
        var randomNum = ((Math.random () * 2 | 0) + 1) - 1; // random number between 0 and 1
        console.log (this.data[randomNum].name + " " + this.data[randomNum].age);
    }
}
// Assign the showData method of the user object to a variable
var showDataVar = user.showData;
showDataVar (); // Samantha 12 (from the global data array, not from the local data array)
/*
This happens because showDataVar () is executed as a global function and use of this inside 
showDataVar () is bound to the global scope, which is the window object in browsers.
*/
// Bind the showData method to the user object
var showDataVar = user.showData.bind (user);
// Now the we get the value from the user object because the this keyword is bound to the user object
showDataVar (); // P. Mickelson 43
bind()允许我们借用方法
// Here we have a cars object that does not have a method to print its data to the console
var cars = {
    data:[
       {name:"Honda Accord", age:14},
       {name:"Tesla Model S", age:2}
   ]
}
// We can borrow the showData () method from the user object we defined in the last example.
// Here we bind the user.showData method to the cars object we just created.
cars.showData = user.showData.bind (cars);
cars.showData (); // Honda Accord 14
这个例子的一个问题是我们showData在cars对象上添加了一个新方法,我们可能不想这样做只是为了借用一个方法,因为汽车对象可能已经有一个属性或方法名showData。我们不想意外覆盖它。正如我们将在下面的讨论中看到的Apply那样Call,最好使用Applyor方法借用一个Call方法。
bind()允许我们柯里化一个函数
函数柯里化,也称为部分函数应用,是使用一个函数(接受一个或多个参数)返回一个新函数,其中一些参数已经设置。
function greet (gender, age, name) {
    // if a male, use Mr., else use Ms.
    var salutation = gender === "male" ? "Mr. " : "Ms. ";
    if (age > 25) {
        return "Hello, " + salutation + name + ".";
    }else {
        return "Hey, " + name + ".";
    }
 }
我们可以使用bind()curry 这个greet函数
// So we are passing null because we are not using the "this" keyword in our greet function.
var greetAnAdultMale = greet.bind (null, "male", 45);
greetAnAdultMale ("John Hartlove"); // "Hello, Mr. John Hartlove."
var greetAYoungster = greet.bind (null, "", 16);
greetAYoungster ("Alex"); // "Hey, Alex."
greetAYoungster ("Emma Waterloo"); // "Hey, Emma Waterloo."
apply()或call()设置此值
、和方法都用于在调用方法时设置 this 值,它们以稍微不同的方式进行设置,以允许在我们的 JavaScript 代码中使用直接控制和多功能性apply。callbind
apply和call方法在设置 this 值时几乎相同,只是您将函数参数作为数组传递给,apply ()而您必须单独列出参数才能将它们传递给call ()方法。
这是在回调函数中使用call或apply设置它的一个示例。
// Define an object with some properties and a method
// We will later pass the method as a callback function to another function
var clientData = {
    id: 094545,
    fullName: "Not Set",
    // setUserName is a method on the clientData object
    setUserName: function (firstName, lastName)  {
        // this refers to the fullName property in this object
        this.fullName = firstName + " " + lastName;
    }
};
function getUserInput (firstName, lastName, callback, callbackObj) {
     // The use of the Apply method below will set the "this" value to callbackObj
     callback.apply (callbackObj, [firstName, lastName]);
}
// The clientData object will be used by the Apply method to set the "this" value
getUserInput ("Barack", "Obama", clientData.setUserName, clientData);
// the fullName property on the clientData was correctly set
console.log (clientData.fullName); // Barack Obama
apply用or借用函数call
借用数组方法
让我们创建一个array-like对象并借用一些数组方法来操作我们的类数组对象。
// An array-like object: note the non-negative integers used as keys
var anArrayLikeObj = {0:"Martin", 1:78, 2:67, 3:["Letta", "Marieta", "Pauline"], length:4 };
 // Make a quick copy and save the results in a real array:
 // First parameter sets the "this" value
 var newArray = Array.prototype.slice.call (anArrayLikeObj, 0);
 console.log (newArray); // ["Martin", 78, 67, Array[3]]
 // Search for "Martin" in the array-like object
 console.log (Array.prototype.indexOf.call (anArrayLikeObj, "Martin") === -1 ? false : true); // true
另一种常见的情况是转换arguments为数组如下
  // We do not define the function with any parameters, yet we can get all the arguments passed to it
 function doSomething () {
    var args = Array.prototype.slice.call (arguments);
    console.log (args);
 }
 doSomething ("Water", "Salt", "Glue"); // ["Water", "Salt", "Glue"]
借用其他方法
var gameController = {
     scores  :[20, 34, 55, 46, 77],
     avgScore:null,
     players :[
          {name:"Tommy", playerID:987, age:23},
          {name:"Pau", playerID:87, age:33}
     ]
 }
 var appController = {
     scores  :[900, 845, 809, 950],
     avgScore:null,
     avg     :function () {
             var sumOfScores = this.scores.reduce (function (prev, cur, index, array) {
                  return prev + cur;
         });
         this.avgScore = sumOfScores / this.scores.length;
     }
   }
   // Note that we are using the apply () method, so the 2nd argument has to be an array
   appController.avg.apply (gameController);
   console.log (gameController.avgScore); // 46.4
   // appController.avgScore is still null; it was not updated, only gameController.avgScore was updated
   console.log (appController.avgScore); // null
用于apply()执行可变参数函数
这Math.max是可变参数函数的一个例子,
// We can pass any number of arguments to the Math.max () method
console.log (Math.max (23, 11, 34, 56)); // 56
但是如果我们有一个数字数组要传递给Math.max呢?我们不能这样做:
var allNumbers = [23, 11, 34, 56];
// We cannot pass an array of numbers to the the Math.max method like this
console.log (Math.max (allNumbers)); // NaN
这就是该apply ()方法帮助我们执行可变参数函数的地方。代替上述方法,我们必须使用apply () 传递数字数组,因此:
var allNumbers = [23, 11, 34, 56];
// Using the apply () method, we can pass the array of numbers:
console.log (Math.max.apply (null, allNumbers)); // 56
    Call、Apply 和 Bind 的基本区别是:
如果您希望执行上下文出现在图片的后面,将使用绑定。
前任:
var car = { 
  registrationNumber: "007",
  brand: "Mercedes",
  displayDetails: function(ownerName){
    console.log(ownerName + ' this is your car ' + '' + this.registrationNumber + " " + this.brand);
  }
}
car.displayDetails('Nishant'); // **Nishant this is your car 007 Mercedes**
假设我想在其他变量中使用此方法
var car1 = car.displayDetails('Nishant');
car1(); // undefined
要在其他变量中使用 car 的引用,您应该使用
var car1 = car.displayDetails.bind(car, 'Nishant');
car1(); // Nishant this is your car 007 Mercedes
下面说一下bind函数的更广泛的使用
var func = function() {
 console.log(this)
}.bind(1);
func();
// Number: 1
为什么?因为现在 func 与数字 1 绑定,如果我们在这种情况下不使用绑定,它将指向全局对象。
var func = function() {
 console.log(this)
}.bind({});
func();
// Object
当您要同时执行语句时,使用调用、应用。
var Name = { 
    work: "SSE",
    age: "25"
}
function displayDetails(ownerName) {
    console.log(ownerName + ", this is your name: " + 'age' + this.age + " " + 'work' + this.work);
}
displayDetails.call(Name, 'Nishant')
// Nishant, this is your name: age25 workSSE
// In apply we pass an array of arguments
displayDetails.apply(Name, ['Nishant'])
// Nishant, this is your name: age25 workSSE
    call/apply立即执行函数:
func.call(context, arguments);
func.apply(context, [argument1,argument2,..]);
bind不会立即执行函数,而是返回包装的apply函数(供以后执行):
function bind(func, context) {
    return function() {
        return func.apply(context, arguments);
    };
}
    调用应用和绑定。以及它们有何不同。
让我们学习使用任何日常术语的呼叫和应用。
你有三辆汽车your_scooter , your_car and your_jet,它们以相同的机制(方法)开始。automobile我们用一个方法创建了一个对象push_button_engineStart。
var your_scooter, your_car, your_jet;
var automobile = {
        push_button_engineStart: function (runtime){
        console.log(this.name + "'s" + ' engine_started, buckle up for the ride for ' + runtime + " minutes");
    }
}
让我们了解何时调用和应用。让我们假设您是一名工程师并且您有your_scooter,your_car并且your_jet没有附带 push_button_engine_start,并且您希望使用第三方push_button_engineStart。
如果您运行以下代码行,它们将给出错误。为什么?
//your_scooter.push_button_engineStart();
//your_car.push_button_engineStart();
//your_jet.push_button_engineStart();
automobile.push_button_engineStart.apply(your_scooter,[20]);
automobile.push_button_engineStart.call(your_jet,10);
automobile.push_button_engineStart.call(your_car,40);
所以上面的例子成功地给 your_scooter, your_car, your_jet 一个来自汽车对象的特征。
让我们深入研究
这里我们将拆分上面的代码行。 
automobile.push_button_engineStart正在帮助我们获得正在使用的方法。
此外,我们使用点符号来应用或调用。 
automobile.push_button_engineStart.apply()
现在应用并调用accept两个参数。
所以这里我们在最后一行代码中设置上下文。
automobile.push_button_engineStart.apply(your_scooter,[20])
call 和 apply 之间的区别只是 apply 接受数组形式的参数,而 call 只接受逗号分隔的参数列表。
什么是 JS 绑定功能?
绑定函数基本上是绑定某物的上下文,然后将其存储到变量中以供稍后执行。
让我们把前面的例子做得更好。前面我们使用了一个属于汽车对象的方法,并用它来装备your_car, your_jet and your_scooter。现在让我们想象一下,我们希望push_button_engineStart在执行的任何后期阶段分别单独启动我们的汽车。
var scooty_engineStart = automobile.push_button_engineStart.bind(your_scooter);
var car_engineStart = automobile.push_button_engineStart.bind(your_car);
var jet_engineStart = automobile.push_button_engineStart.bind(your_jet);
setTimeout(scooty_engineStart,5000,30);
setTimeout(car_engineStart,10000,40);
setTimeout(jet_engineStart,15000,5);
还不满意?
让我们像泪珠一样清楚。是时候做实验了。我们将返回调用并应用函数应用程序,并尝试将函数的值存储为引用。
下面的实验失败了,因为 call 和 apply 是立即调用的,因此,我们永远不会到将引用存储在变量中的阶段,而这正是 bind 函数抢镜的地方
var test_function = automobile.push_button_engineStart.apply(your_scooter);
句法
这里
function printBye(message1, message2){
    console.log(message1 + " " + this.name + " "+ message2);
}
var par01 = { name:"John" };
var msgArray = ["Bye", "Never come again..."];
printBye.call(par01, "Bye", "Never come again...");
//Bye John Never come again...
printBye.call(par01, msgArray);
//Bye,Never come again... John undefined
//so call() doesn't work with array and better with comma seperated parameters 
//printBye.apply(par01, "Bye", "Never come again...");//Error
printBye.apply(par01, msgArray);
//Bye John Never come again...
var func1 = printBye.bind(par01, "Bye", "Never come again...");
func1();//Bye John Never come again...
var func2 = printBye.bind(par01, msgArray);
func2();//Bye,Never come again... John undefined
//so bind() doesn't work with array and better with comma seperated parameters
const person = {
    name: "Lokamn",
    dob: 12,
    print: function (value,value2) {
        console.log(this.dob+value+value2)
    }
}
const anotherPerson= {
     name: "Pappu",
     dob: 12,
}
 person.print.call(anotherPerson,1,2)
    name: "Lokamn",
    dob: 12,
    print: function (value,value2) {
        console.log(this.dob+value+value2)
    }
}
const anotherPerson= {
     name: "Pappu",
     dob: 12,
}
 person.print.apply(anotherPerson,[1,2])
**调用和应用函数是不同的调用采用单独的参数,但应用采用数组,如:[1,2,3] **
    name: "Lokamn",
    dob: 12,
    anotherPerson: {
        name: "Pappu",
        dob: 12,
        print2: function () {
            console.log(this)
        }
    }
}
var bindFunction = person.anotherPerson.print2.bind(person)
 bindFunction()
    调用:调用调用函数,并允许您一一传递参数
Apply: Apply 调用函数并允许您将参数作为数组传递
Bind: Bind 返回一个新函数,允许您传入一个 this 数组和任意数量的参数。
var person1 = {firstName: 'Raju', lastName: 'king'};
var person2 = {firstName: 'chandu', lastName: 'shekar'};
function greet(greeting) {
    console.log(greeting + ' ' + this.firstName + ' ' + this.lastName);
}
function greet2(greeting) {
        console.log( 'Hello ' + this.firstName + ' ' + this.lastName);
    }
greet.call(person1, 'Hello'); // Hello Raju king
greet.call(person2, 'Hello'); // Hello chandu shekar
greet.apply(person1, ['Hello']); // Hello Raju king
greet.apply(person2, ['Hello']); // Hello chandu shekar
var greetRaju = greet2.bind(person1);
var greetChandu = greet2.bind(person2);
greetRaju(); // Hello Raju king
greetChandu(); // Hello chandu shekar
call() :-- 这里我们单独传递函数参数,而不是数组格式
var obj = {name: "Raushan"};
var greeting = function(a,b,c) {
    return "Welcome "+ this.name + " to "+ a + " " + b + " in " + c;
};
console.log(greeting.call(obj, "USA", "INDIA", "ASIA"));
apply() :-- 这里我们以数组格式传递函数参数
var obj = {name: "Raushan"};
var cal = function(a,b,c) {
    return this.name +" you got " + a+b+c;
};
var arr =[1,2,3];  // array format for function arguments
console.log(cal.apply(obj, arr)); 
绑定():-
       var obj = {name: "Raushan"};
       var cal = function(a,b,c) {
            return this.name +" you got " + a+b+c;
       };
       var calc = cal.bind(obj);
       console.log(calc(2,3,4));
    想象一下,绑定不可用。您可以按如下方式轻松构建它:
var someFunction=...
var objToBind=....
var bindHelper =  function (someFunction, objToBind) {
    return function() {
        someFunction.apply( objToBind, arguments );
    };  
}
bindHelper(arguments);
        function sayHello() {
            //alert(this.message);
            return this.message;
    }
    var obj = {
            message: "Hello"
    };
    function x(country) {
            var z = sayHello.bind(obj);
            setTimeout(y = function(w) {
//'this' reference not lost
                    return z() + ' ' + country + ' ' + w;
            }, 1000);
            return y;
    }
    var t = x('India')('World');
    document.getElementById("demo").innerHTML = t;
    使用 bind 来调用函数。两者都apply调用call函数。
bind()还允许附加参数附加到 args 数组。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind
简单来说,所有方法都用于在常规函数中显式设置上下文(this)
调用:调用在给定上下文中调用函数并允许一一传递参数
Apply:apply 在给定的上下文中调用函数并允许将参数作为数组传递
绑定:绑定通过设置提供的上下文返回一个新函数,并允许一个一个传递参数
笔记:
我认为它们相同的地方是:它们都可以更改函数的 this 值。它们的区别是:绑定函数将返回一个新函数作为结果;call 和 apply 方法会立即执行函数,但 apply 可以接受一个数组作为参数,它会解析数组分离。而且,绑定函数可以是 Currying。
当我们想要分配具有特定上下文的函数时,应该使用绑定函数,例如。
var demo = {
           getValue : function(){ 
             console.log('demo object get value       function') 
            }
           setValue : function(){  
              setTimeout(this.getValue.bind(this),1000)           
           }
 }
在上面的示例中,如果我们调用 demo.setValue() 函数并直接传递 this.getValue 函数,那么它不会直接调用 demo.setValue 函数,因为 setTimeout 中的 this 引用窗口对象,所以我们需要将演示对象上下文传递给 this.getValue函数使用绑定。这意味着我们只传递带有演示对象上下文的函数,而不是实际调用函数。
希望你明白。
更多信息请参考 javascript绑定函数了解详细