OOP Flashcards

1
Q

What is a method?

A

It’s a function stored as a property of an object

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

How can you tell the difference between a method definition and a method call?

A

Definition: definition has parameters
Must be in the object literal, property and function inside the curly braces
Var object = {
add: function (x, y) {
return x + y;
}
};
Call: call has values in the space of the parameters
object.method(possible argument)

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

Describe method definition syntax (structure).

A

Var object = {
add: function (x, y) {
return x + y;
}
};

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

Describe method call syntax (structure).

A

object.method(possible argument)

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

How is a method different from any other function?

A

Give the object name and the property name
Method name has a period before it with and attached to an object

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

What is the defining characteristic of Object-Oriented Programming?

A

The object can contain data(as properties) and behavior (as methods)
Able to pairing data with behavior in the same space(in an object)

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

What are the four “principles” of Object-Oriented Programming?

A

Abstraction
Encapsulation
Inheritance
Polymorphism

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

What is “abstraction”?

A

Kind of like generalization, where you are focusing more on the important points of what something is doing rather than focusing on every nitty gritty detail
Way to use a complex tool and have a simple interface to be able to use it in a simple way
i.e. light switch, we don’t have to touch electrical wires to turn on the lights

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

What does API stand for?

A

Application Programming Interface

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

What is the purpose of an API?

A

It’s a way for 2 or more computer programs to communicate with each other.
It’s abstractions created for systems to talk with each other
DOM is an API
Directly interact with output on the screen using javascript
It’s an intermediary using the tools someone created to so we can use it to do something
.createElement is an object someone created the hard work and gave us access to the object so we can create elements without understanding the complex behavior of that object

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

What is this in JavaScript?

A

It’s an implicit parameter for an object and can be given value depending on when it’s called

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

What does it mean to say that this is an “implicit parameter”?

A

It doesn’t start with a value. It is only given a value inside of whatever the object it is being called in at when it’s being called

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

When is the value of this determined in a function; call time or definition time?

A

Call time

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

What does this refer to in the following code snippet?
var character = {
firstName: ‘Mario’,
greet: function () {
var message = ‘It's-a-me, ‘ + this.firstName + ‘!’;
console.log(message);
}
};

A

Nothing at the time since it isn’t being called. Doesn’t exist.

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

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

‘It’s-a-me Mario!”
Because greet is being called off of character and the code block is invoked and called.
The object before the period before greet, that means this is the character object.

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

Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();

A

It’s-a-me undefined!
Because window.firstName = undefined
This is because the object is not written before the method when this is being called. Technically, then window.hello() is what’s called, thus undefined

17
Q

How can you tell what the value of this will be for a particular function or method definition?

A

Nothing during a definition time

18
Q

How can you tell what the value of this is for a particular function or method call?

A

If there’s an object on the left side of the period, that’s the value
If there’s nothing, then it’s window, thus default

19
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based or prototypal inheritance

20
Q

What is a prototype in JavaScript?

A

It’s an object that stores properties and methods we want to use on other objects
It’s the object that other objects reference for the properties and methods

21
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

The tools needed is stored in the prototype object and we can reference it via the method because it’s already stored in the prototype object

22
Q

If an object does not have its own property or method by a given key, where does JavaScript look for it?

A

Prototype of that object, starting at the local object

23
Q

What does the new operator do?

A

Creates a blank, plain JS object
The new object prototype property (__proto__) points to the constructor function’s prototype property and gets the same value like the other values
So now, the new object can have access to the same prototype property with the functions in there
Execute the constructor function with the given argument
The constructor function is now able to run the function in the prototype property from the “older function” with all the new properties now assigned in the new object.
The new object gets returned as the return value
Constructor functions do not return anything

24
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

Prototype property

25
Q

What does the instanceof operator do?

A

Checks if the object was made by that function