Jesufer Vn
Jesufer Vn

Reputation: 13760

How to pass events as parameters?

I want to have a collection of functions in the class T, defined below.

function T(){
    this.Funcs = new Array();
    this.appendEvt=function(Obj, Evt, Act){
        switch(Evt){
            case "onclick":
                this.Funcs.push(function(){Obj.onclick=Act;});
                break;
    }       
};

These functions are stored in a array of class T (Funcs). This functions must be of the form:

Funcs[i]=function(){Obj.Event=FuncWhichContainsActionsWhenTheEventIsTriggered;}

The question is, how can I pass as a parameter any event, like onclick, or "onmouseover,..., so I am able to rewrite the function this.appendEvt like this?:

    this.appendEvt=function(Obj, Evt, Act){
        this.Funcs.push(function(){Obj.Evt=Act;});      
};

Upvotes: 0

Views: 131

Answers (1)

Tikhon Jelvis
Tikhon Jelvis

Reputation: 68152

You can just use "[]":

Obj[Evt] = Act;

Upvotes: 1

Related Questions