this should refer the object itself but in the following code why it's behaving differently?
var x = 4,
obj = {
x: 3,
bar: function() {
var x = 2;
setTimeout(function() {
var x = 1;
alert(this.x);
}, 1000);
}
};
obj.bar();
Why the alert is 4
instead of 3
?