bind方法并没有将变量't'作为新的'this'关键字传递给"ob.bind_part()'对象文字函数。
然而,如果使用“call”而不是“bind”
var ob = {
"first": function() {
console.log("first function");
var t = "new bind";
ob.bind_part.bind(t);
},
"bind_part": function() {
console.log(this.toString());
}
};
(function() {
ob.first();
ob.bind_part(); // returns the 'ob' object instead of the bind
})();
ob.bind_part.call(t); //THIS WORKS
它能工作吗?
为什么绑定(bind)不起作用呢?有什么想法吗?
谢谢。