If it bind(obj)can return a function c thisbound to obj, then it won’t
fn.bind(obj1).bind(obj2)
returns the function c thisassociated with obj2?
It seems that only the first binding will bind it, regardless of the second binding, or if we bind it twice or more? Is this part of the specifications?
Example: http://jsfiddle.net/hah0L3nj/
var obj1 = { name: "Mike" },
obj2 = { name: "Mary" };
console.log(obj1, obj2);
function printName() {
console.log(this.name);
}
printName.bind(obj1)();
printName.bind(obj2)();
printName.bind(obj1).bind(obj2)();
The last line will print "Mike."
I think the reason is that it bindruns like this:
Function.prototype.myBind = function (obj) {
var self = this;
return function () {
self.call(obj);
}
};
see http://jsfiddle.net/hah0L3nj/1/
, , , ( ) . , bind , .