Constructor, operator "new" Flashcards
Constructor functions technically are regular functions. There are two conventions though:
They are named with capital letter first.
They should be executed only with “new” operator.
When a function is executed with new, it does the following 3 steps
A new empty object is created and assigned to this.
The function body executes.
The value of this is returned.
Usually, constructors do not have a return statement. Their task is to write all necessary stuff into this, and it automatically becomes the result.
But if there is a return statement, then the rule is simple:
If return is called with an object, then the object is returned instead of this.
If return is called with a primitive, it’s ignored.
Constructor functions should only be called using ______
new
We can use constructor functions to make ______
multiple similar objects.