This question is from ECMA-262 quiz
var x = 100;
var foo = {
x: 50,
bar: function(){
return this.x;
}
}
console.log(foo.bar()); //returns 50
console.log((foo.bar = foo.bar)()); //returns 100
How does the this context changes in the second console statement ? or in general what object does equals to(assigning) operation returns the global object ?
foo.bar(a member operator) evaluates to a Reference “the property “bar” on an object“, and this will be treated special when calling it.(foo.bar = foo.bar)(an assignment) just yields the assigned value, and calling it will result in the global object being used asthis.