0

this is my main problem while using javascript objects. if theres another function in method this explains that function or element object. and i want to fire my dinamic object method in that function. How can i do that? Thanks for help.

Here's an example code:

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");

0 Answers0