我在Javascript中有一组全局计数器变量:
var counter_0 = 0;
var counter_1 = 0;
var counter_2 = 0;
等等
然后,我有了一个Javascript函数,该函数接受一个映射到这些全局计数器的“索引”数字。在此函数内部,我需要使用传递给该函数的“索引”值来读写这些全局计数器。
我希望它如何工作的示例,但是当然根本不起作用:
function process(index) {
// do some processing
// if 'index' == 0, then this would be incrementing the counter_0 global variable
++counter_+index;
if (counter_+index == 13)
{
// do other stuff
}
}
我希望我要实现的目标是明确的。如果没有,我会尽力澄清。谢谢。
编辑说明:
我不是要增加计数器的名称,而是要增加计数器包含的值。
拉风的咖菲猫
慕码人8056858
芜湖不芜
相关分类