Kindly I am a beginner student in the javascript world, and I stopped studying on the point that the new
keyword points to the newly created object, let's write some code and then ask my question.
function Employee(name) {
this.name = name;
}
var x = new Employee("youhana");
how does new keyword forced this keyword to point to the x
object despite the expression didn't reached the end, I mean
var x = new Employee("youhana");
Firstly, the =
operand will wait to the end of the expression evaluation of new Employee("youhana");
to be ended, then it will assign the final value of this expression and put it to x
which will be object,
another example:
function Book(){
**/*at this point, there's is no relation between the new object that will be created after this block of code ended, so how new keyword in this point knew that the new object **will** be obj and **this** will point to it?*/**
}
var obj = new Book();