When Im reading this,It tells me that "A new instance of the given target, created by calling it (or newTarget, if present) as a constructor with the given arguments." But in reality, it is not the case at all. Here is an example:
function Parent() {
this.parent = "Parent"
console.log("This is parent.")
}
function Child() {
this.child = "Child"
console.log("This is child.")
}
var result = Reflect.construct(Parent, [], Child);
console.log(result)
The output looks like this:
This is acting so weird to me because base on the doc, when we put Child as new target parameter in Reflect.construct, it should use constructor of Child to make a new instance, but the log shows "This is parent." is printed and property of Parent is saved while at the same time constructor is of Child(). How could this be possible? Can someone please explain what is happening behind the scene? This is driving me crazy, I really want to know how javascript does this. Thank you so much guys.