I've got some weird behavior with a for-in loop.
Code:
var obj = {
q:1,
w:2,
e:4,
r:5
};
function test(data) {
for (key in data) {
//do sth;
}
}
!function() {
for (key in obj) {
console.log(key);
test({a:1,b:2,c:3});
console.log(key);
}
}();
as i expected the output should be sth like this:
q q w w e e r r
but i got this:
q c w c e c r c
i can't find the logic behind this behavior! the key variables are scoped lexically ! what's worng with my code?