0
使用全局变量,我想执行以下代码:的Javascript:在函数定义
for (var i = 0; i <= 9; ++i) {
State.prototype["button" + i.toString()] = function() {
console.log("I am a digit button" + i.toString());
this.setValue(i.toString());
};
}
但它是错误的,因为所有的函数创建的变量i是常见的。 比如我想要的功能State.prototype.button0()的工作为:
console.log("I am a digit button" + "0");
this.setValue("0");
怎么办呢?
是的,这是它,谢谢! – maximus 2013-03-26 10:43:28