(More) Advanced JavaScript Flashcards
Why do we need a single source of truth? (from data modeling)
- Place to store our data for when we need to manipulate it
- Easier to access and update
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
Why are parent - child relationships important in OOP?
Modeling the real world using data, show how groups of information are related to and relent on each other
**OOP confined to their bubble –> create a tether from one bubble to another
What is the basic idea of OOP?
MDN - The basic idea of OOP is that we use objects to model real world things that we want to represent inside our programs, and/or provide a simple way to access functionality that would otherwise be hard or impossible to make use of.
LFZ - creating a separate space and organization for keeping everything together and pairing data and functionality
Why did you have to bind this for the feedChild method in the Parent class?
Otherwise the this will be the Child class
Why is it important to assign callback methods to properties in the constructor?
So they will be added to the each object instance upon creation and can be used in each object
Why did the Maker class require all of the Parent class info?
The maker class instantiating the parent class
Why did you have to bind this for the replenishFood method.
Otherwise the this will be the parent class
What decides the order in which JS files must be loaded?
HTML document, what is getting instantianted by what and what data is needed by what objects
Instantiation (definition)
The process of taking a class definition and creating an object (or instance) from it
Instance (definition)
the object that is created from the instantiation process
What are classes?
Syntactical sugar for prototypical inheritance modeled after object oriented programming languages; special functions
Polymorphism (definition)
The ability of multiple object types to implement the same functionality MDN - In the case of OOP, by making the class responsible for its code as well as its own data, polymorphism can be achieved in that each class has its own function that (once called) behaves properly for any object.
Constructor functions
Used to define and initialize objects and their features
MDN - The Function constructor creates a new Function object. Calling the constructor directly can create functions dynamically, but suffers from security and similar (but far less significant) performance issues to eval. However, unlike eval, the Function constructor creates functions which execute in the global scope only.