javascript-constructors Flashcards
What does the new operator do?
the new operator lets a dev create instances of an object
4 things:
1. creates a blank object
2. points the __proto__ property of the newlyCreatedInstance to the .prototype property of the constructor function
3. execute the constructor function w the given arguments binding newly created instance to this (i.e any reference to this in the constructor function now refers to the newlyCreatedInstance).
4 if the constructor returns an object this becomes the value of the entire new expression but if the return is a primitive, newlyCreatedInstance is returned instead
What property of JavaScript functions can store shared behavior for instances created with new?
.prototype property
What does the instanceof operator do?
checks if the object has a certain prototype