functin A(){}//定义类AA.prototype.a=function(){
var div = document.createElement("div");
div.onclick=function(){ ..... }
}//初始化函数A.prototype.b()=function(){}
我要在div.onclick处理函数中调用A.b()方法,请问如何获取类A的实例?//应用时如下操作
var AAA = new A();
AAA.a();
var div = document.createElement("div");
div.onclick=function(){ ..... }
}//初始化函数A.prototype.b()=function(){}
我要在div.onclick处理函数中调用A.b()方法,请问如何获取类A的实例?//应用时如下操作
var AAA = new A();
AAA.a();
A.prototype.a = function(){
var div = document.createElement("div");
var self = this;
div.onclick=function(){ alert(self.a); }
}
functin A(){}//定义类AA.prototype.a=function(){
var self = this;
var div = document.createElement("div");
div.onclick=function(){ self.b() };
}//初始化函数A.prototype.b()=function(){}
var div = document.createElement("div");
var self = this;
div.onclick=function(){ alert(self.a); }
}