开发者

How to pass events as parameters?

开发者 https://www.devze.com 2023-03-06 01:39 出处:网络
I want to have a collection of functions in the class T, defined below. function T(){ this.Funcs = new Array();

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


You can just use "[]":

Obj[Evt] = Act;
0

精彩评论

暂无评论...
验证码 换一张
取 消