开发者

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


You can just use "[]":

Obj[Evt] = Act;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜