Enough Gyan! Lets code:
(Note Capital P in Programmer, this is the notion used for constructors,first capital alphabet.)
Above code creates an object and assign appropriate values to it using self defined constructor.
Role of new keyword-
- Creates an empty object which is referenced by “this” keyword which inherits the prototype of the function.
- Returns object referred by this if no object is returned explicitly.
We can imagine the role of new keyword as:
Another thing which you will want to consider while creating constructors will be exploiting prototype property of a constructor.