JS OOP Flashcards

1
Q

What is a method?

A

a function which is a property of an object. In JS functions themselves are objects. So a method is actually an object reference to a function.

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

What does a method do?

A

they are actions that can be performed on objects

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

What is this?

A

this keyword refers to the object it belongs to. It refers to the global object in a function

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

What does bind do?

A

bind() method creates a new function when invoked, has the this sets to the provided value. It allows an object to borrow a method from another object without making a copy of that method

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

a function you create an object that can be instantiated into multiple instances, while the literal notation delivers a single object.

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

What is Prototypal Inheritance?

A

inheritance from other prototypes of Objects

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

What is the Prototypal Chain?

A

all objects in JS are instances of objects which sits on the top of the prototypal chain

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

In the custom object we created, where did the other __proto__ come from?

A

from the curly braces

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

Why does JS have prototypal inheritance?

A

when you create it once, you save memory when you only need to do it once. Basically for the sake of memory

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 an empty object, then sets the constructor object to another object, then it gets passed into the function as this, lastly returns this if the function doesn’t return an 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

because of inheritance and memory efficiency

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

calls the constructor function

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

classes don’t hoist. functions can hoist

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

What is a static method?

A

they are not called on instances of the class but instead they’re called on the class itself

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

it enables you to group classes that are only used in one place.

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

you can reuse functionality common to all the object types rather than having to duplicate it. By having connection with class within another class.

17
Q

What is the basic idea of OOP?

A

we use objects to model real world things that we want to represent inside our programs or provide a simple way to access functionality that would otherwise be hard. To avoid spaghetti code.

18
Q

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

A

in order to save it. to reference it in the future

19
Q

Why did the maker class require all the parent class info?

A

the maker is responsible for making the parent class

20
Q

Why did you have to bind this for the replenishfood method?

A

so that it would work when passed forward to the parent class

21
Q

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

A

if its calling a data, you have to include it first. If you want to use a tool, it needs to exist already.