3

我有以下 ExtJS 控制器代码:

init: function() {
    this.control({
        '#menuitem-A': { click: this.handlerA },
        '#menuitem-B': { click: this.handlerB },
    });
},

和以下事件处理程序:

commonFunc: function(param1, param2) {
    // do something with param1 and param2 in here
},

handlerA: function(button, event) {
    this.commonFunc('param-A1', 'param-A2');
},

handlerB: function(button, event) {
    this.commonFunc('param-B1', 'param-B2');
},

问题:当前代码是多余的:handlerA只是handlerBcommonFunc不同的参数调用

问题:对于不同的事件处理程序, 我想删除handlerAandhandlerB而不是call或上面带有任意参数apply的通用函数和函数。是否可以?commonFunchandlerAhandlerB

例子:

init: function() {
    this.control({
        '#menuitem-A': { click: /*commonFunc with ['param-A1', 'param-A2']*/ },
        '#menuitem-B': { click: /*commonFunc with ['param-B1', 'param-B2']*/ },
    });
},

非常感谢!

4

1 回答 1

5

这个怎么样:

init: function() {
    this.control({
        '#menuitem-A': { 
            click: function(button, event){
                this.commonFunc('param-A1', 'param-A2');
            }
        },
        '#menuitem-B': { 
            click: function(button, event){
                this.commonFunc('param-B1', 'param-B2');
            }
        }
    });
},
于 2012-07-04T13:20:47.870 回答