var f = function() {
this.x = 5;
(function() {
this.x = 3;
})();
console.log(this.x);
};
var obj = {
x: 4,
m: function() {
console.log(this.x);
}
};
f(); // 3
new f(); // 5
f.call(f); // 5
obj.m.call(f); // 5
If you call the function, the result is 3, but if you bind the context with f.call(f) - the result is 5. Also, if I call the functions as a constructor. Why it happens? Sorry for the stupid question, but I tried to find the answer, but could not.