Take in consideration this code:
function a() {
alert(this.variable);
}
b = new function() {
this.variable = "abc";
a.call(this);
}
Is there a way to auto override context instead of using the call method? like this (not working):
function a() {
var _this = Function.caller;
alert(_this.variable);
}
b = new function() {
this开发者_运维百科.variable = "abc;
a();
}
Thanks in advance.
If you want a
to have access to b
's this
, you'll have to pass this
explicitly, i.e. instead of a()
do a(this)
.
精彩评论