设置JavaScript以调用具有不同参数的函数

Jos*_*mit 3 javascript extjs extjs4 extjs-mvc extjs4.1

我有以下ExtJS控制器代码:

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

和以下事件处理程序:

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');
},
Run Code Online (Sandbox Code Playgroud)

问题:当前的代码是多余的:handlerAhandlerB只需要调用commonFunc不同的参数

问题:对于不同的事件处理程序, 我想删除handlerAhandlerB替换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']*/ },
    });
},
Run Code Online (Sandbox Code Playgroud)

非常感谢!

red*_*d-X 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');
            }
        }
    });
},
Run Code Online (Sandbox Code Playgroud)