I am trying to execute the following code:
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());
    };
}
But it is wrong, because the i variable is common for all the function created. For example I want the function State.prototype.button0() to work as:
console.log("I am a digit button" + "0");
this.setValue("0");
How to do it?
 
     
    