<分区>
在下面的代码中,我尝试创建几个处理程序函数,这些函数必须调用存储在函数数组(“buttonHandlers”)中的不同函数。该数组是外部作用域的一部分:
buttonJson = {};
for (i = 0; i < buttonNames.length; i++) {
customHandler = buttonHandlers[i];
buttonJson[buttonNames[i]] = function() {
customHandler.apply();
$('#msg-dialog-confirm').dialog("close");
$('body').remove('#msg-dialog-confirm');
...
};
}
上面的代码导致处理函数调用函数数组的最后一个数组元素('buttonHandlers')。我希望每个处理函数只调用相关数组索引指定的关联函数。我怎样才能做到这一点?