(More) Advanced JavaScript Flashcards
What is a method?
Function on an object
What does a method do?
Whatever you tell it to do like functions
What is this?
refers to the object that the function was declared in (either an object itself or the window)
What does bind do?
bind is a method that changes ‘this’ to whatever object is specified in the argument
What is the difference between a function and an object literal?
**functions are CALLABLE objects! have three methods - apply, call, bind!
What is Prototypal Inheritance?
The inheritance of certain methods and properties from the Prototype property of other objects
What is the Prototypal Chain?
The way in which javascript looks for methods or properties in an object; if doesnt find it in this object, will go up to the next prototype in the chain
In the custom objects we created, I noticed that our prototype object has another __proto__ property, where did that come from?
Created a new object with {} and inherited from Object
Why does JavaScript have Prototypal Inheritance?
Efficiency and memory (how much memory RAM your program takes up)
use as little memory as possible
What does the new keyword do?
- creates a blank JS object
- sets the constructor of this new object to another object
- the new object becomes the “this”
- returns this new object
I could’ve added a method to the constructor function by assigning a method to a property on the this object. Why do we have to add it to the prototype property?
** save memory and space
What is the first thing that happens in a class when it is instantiated with the new keyword?
The constructor runs to create a new object using the specified arguments
Since classes are technically functions as well. Can you name a difference between classes and functions?
Class are not hoisted like functions are
What is a static method?
Static methods are called without instantiating their class and cannot be called through a class instance.
- *Static methods are utility functions
- *can use without creating an instance, attached to creator Array, Object
ex. Array.isArray(arr) // true
What is the benefit of instantiating Classes within other classes?
- Has a tie from the parent to child, parent always has reference to the child
- pass in info from parent to child