I know this is empty in the beginning of a contructor function, and gets filled until it's automatically returned.
function Elf(_name, _weapon) {
//empty this
console.log('this a', this); // {}
this.name = _name;
this.weapon = _weapon;
// this with props
console.log('this b', this); // {name: "Sam", weapon: "bow"}
}
let sam = new Elf("Sam", "bow");
In the node console and this snippet, the result is what i expected:
this a {}
this b { "name": "Sam", "weapon": "bow" }
But in the Chrome's console, i get:
this a Elf {}
name: "Sam"
weapon: "bow"
__proto__: Object
this b Elf {name: "Sam", weapon: "bow"}
name: "Sam"
weapon: "bow"
__proto__: Object
why are those name and weapon properties already filled? If you'r gonna mention hoisting, and that the reference to this becomes global, why the difference between the two logs?