如何将函数的上下文应用于任何 javascript 对象?所以我可以改变函数中“this”的含义。
例如:
var foo = {
a: function() {
alert(this.a);
},
b: function() {
this.b +=1;
alert (this.b);
}
var moo = new Something(); // some object
var moo.func.foo = foo; // right now this is moo.func
// how do I apply/change the context of the foo functions to moo?
// so this should equal moo
moo.a(); // this should work