日期:2014-05-16 浏览次数:20517 次
function A() { this.a = 1; this.f = function () { this.a = 2; return this.a; } } var a = new A(); alert(a.a) a.f(); alert(a.a)
------解决方案--------------------
function A(){
this.a = 1;
this.f = new B();
}
function B(){
this.a = 2;
}
var temp = new A();
alert( temp.f.a);
------解决方案--------------------
function A() { this.a = 1; var sender = this; this.f = function () { sender.a = 2; } } var c = new A(); c.f(); alert(c.a);// 为2