It's not executing before the console.log
, as others mentioned, it is caused by the live reference to that object, so you will always see the newest value of the object.
Check the example
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food() {
console.log(this)
Product.call(this, 'cheese', 5);
console.log(this)
this.category = 'food';
}
new Food()
Update
You can see the current value if you are not opening the object (the first is an empty object {}
, the second got values), I pointed it with arrows. If you open the object you will see the live reference, which is the same for both logs.
