(More) Advanced JavaScript Flashcards

1
Q

What is a method?

A

Function on an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does a method do?

A

Whatever you tell it to do like functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is this?

A

refers to the object that the function was declared in (either an object itself or the window)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does bind do?

A

bind is a method that changes ‘this’ to whatever object is specified in the argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between a function and an object literal?

A

**functions are CALLABLE objects! have three methods - apply, call, bind!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Prototypal Inheritance?

A

The inheritance of certain methods and properties from the Prototype property of other objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the Prototypal Chain?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In the custom objects we created, I noticed that our prototype object has another __proto__ property, where did that come from?

A

Created a new object with {} and inherited from Object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why does JavaScript have Prototypal Inheritance?

A

Efficiency and memory (how much memory RAM your program takes up)
use as little memory as possible

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the new keyword do?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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?

A

** save memory and space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the first thing that happens in a class when it is instantiated with the new keyword?

A

The constructor runs to create a new object using the specified arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Since classes are technically functions as well. Can you name a difference between classes and functions?

A

Class are not hoisted like functions are

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a static method?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the benefit of instantiating Classes within other classes?

A
    • Has a tie from the parent to child, parent always has reference to the child
    • pass in info from parent to child
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why are parent - child relationships important in OOP?

A

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

17
Q

What is the basic idea of OOP?

A

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

18
Q

Why did you have to bind this for the feedChild method in the Parent class?

A

Otherwise the this will be the Child class

19
Q

Why is it important to assign callback methods to properties in the constructor?

A

So they will be added to the each object instance upon creation and can be used in each object

20
Q

Why did the Maker class require all of the Parent class info?

A

The maker class instantiating the parent class

21
Q

Why did you have to bind this for the replenishFood method.

A

Otherwise the this will be the parent class

22
Q

What decides the order in which JS files must be loaded?

A

HTML document, what is getting instantianted by what and what data is needed by what objects

23
Q

Instantiation (definition)

A

The process of taking a class definition and creating an object (or instance) from it

24
Q

Instance (definition)

A

the object that is created from the instantiation process

25
Q

What are classes?

A

Syntactical sugar for prototypical inheritance modeled after object oriented programming languages; special functions

26
Q

Polymorphism (definition)

A
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.
27
Q

Constructor functions

A

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.