calValue: function (data) {
var self = this;
var values = data.values;
for (var i = 0; i < data.length; i++) {
if(data.condition == 0){
(function (values) {
for (i = 0; i < values.length; i++) {
}
})(values)
}
else{
//do sth else
}
}
}
my understanding is each funtion has its own context and the variable being declared inside it, will only be effetive inside. Like above code snippet, i expect the "i" variable inside the inner for-loop won't impact the outer one "i" variable. However, the fact is it do affect.
Could someone please help explain? Thanks.
iin the second inner function, so it's using theifrom the outer function, not its own internal copy.