var a = [];
var b = ['abc','def'];
for(var c of b) {
var c_ = c.slice();
a.push(function(){alert(c_)});
}
a[0]();
a[1]();
Result is seing the message "def" twice. This is entirely unexpected. How do I do this in JavaScript? If it were alert(c)
I could understand but c_
is clearly a copy of c
and is properly scoped by other language's standards.