这是我使用javascript对象时的主要问题。如果方法this
中的另一个函数解释了该函数或元素对象。我想在该功能中解雇我的dinamic对象方法。我怎样才能做到这一点?谢谢你的帮助。
这是一个示例代码:
var myobject = function(param1,param2) {
this.parentElement = element.get(param2); /*element is my helper object*/
this.param1 = param1;
this.param3 = null;
this.isSomething = false;
this.init = function(){
if(this.isSomething){
for(var i=0; i<this.param1.length; i++){
this.param3 = element.create("a");
this.param3.setAttribute("href","javascript:;");
this.param3.innerHTML = i;
this.param3.onclick = function(){
this.action(i); /*my problem is here*/
}
this.parentElement.appendChild(this.param3)
}
}
}
this.action = function(i){
console.log(i);
}
}
var useobject = new myobject(["example","data"],".someselector");