JavaScript Constructors Flashcards
1
Q
What does the new operator do?
A
lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
- Creates a blank, plain JavaScript object.
- Adds a property to the new object (__proto__) that links to the constructor function’s prototype object
- Binds the newly created object instance as the this context (i.e. all references to this in the constructor function now refer to the object created in the first step).
- Returns this if the function doesn’t return an object.
2
Q
What property of JavaScript functions can store shared behavior for instances created with new?
A
prototype property - which defines a property that is shared by all objects created with that function
You can add a shared property to a previously defined object type by using the prototype property
3
Q
What does the instanceof operator do?
A
Operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.