dynobj = {};
methods = ["method1","method2", "method3"];
for (var i = 0; i < methods.length; i++) {
dynobj[methods[i]] = function () {
alert("I am " + i);
};
};
dynobj.method2();
dynobj.method1();
I expect "I am 1" and "I am 0", but have "I am 3" and "I am 3". What the correct way to have behaveary which I expect?