Final Exam Deck #1 Flashcards
What is the root prototype?
Object.prototype
What is returned for the following statement:
Object.getPrototypeOf( [ ] )
Array.prototype
What is returned for the following statement:
Object.getPrototypeOf( )
Object.prototype
How/Where are fields declared in a class?
Fields are declared within the constructor method
How can we add fields or methods to a class after the class has been created?
Ex: For the class “Car”, add a new field “sound”: “vroom”
We can add fields/methods to the prototype which are accessible by all instantiated object:
Car.prototype.sound = “Vroom”
How can we declare private fields within a class?
within the constructor function we do 3 things:
- use “let” to define a private field
- getter function
- setter function
What does a subclass inherit from a superclass?
All its public fields and methods
Does a subclass inherit a superclass’s private members?
No, a child class does not inherit its parent’s private members
How are “extends” and prototypes related?
The “extends” keyword sets a prototype chain where the subclass’s prototype points to the parent class’s prototype
If we don’t define a constructor for a subclass what happens?
A default constructor is created where the first line calls the parents constructor using the “super” keyword
If we override the default constructor for a subclass what must we always do?
The first line of the constructor must always class the parents constructor using “super(parameter)”
Do arrow function have super?
No
What is the python equivalent of a JavaScript object?
A dictionary
If we try to access an object property that does not exist what happens?
That property gets added to the object
What happens when a binding is used without declaration? Ex: x=5
Its automatically added to the “global” object