I was learning details about the new operator in JS and ran the following code in the Node.js repl.
function Foo(){
this.x = "ecks";
this.y = "why";
}
function Foo2(){
this.x = "ecks";
this.y = "why";
return(this);
}
new Foo();
Foo2();
On this page https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new it says that the new operator makes the call to foo return this and it does work. But the second call which explicitly returns this ends up returning the global this. Why is this?