OOP Flashcards
What is a method?
It’s a function stored as a property of an object
How can you tell the difference between a method definition and a method call?
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)
Describe method definition syntax (structure).
Var object = {
add: function (x, y) {
return x + y;
}
};
Describe method call syntax (structure).
object.method(possible argument)
How is a method different from any other function?
Give the object name and the property name
Method name has a period before it with and attached to an object
What is the defining characteristic of Object-Oriented Programming?
The object can contain data(as properties) and behavior (as methods)
Able to pairing data with behavior in the same space(in an object)
What are the four “principles” of Object-Oriented Programming?
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
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
What does API stand for?
Application Programming Interface
What is the purpose of an API?
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
What is this in JavaScript?
It’s an implicit parameter for an object and can be given value depending on when it’s called
What does it mean to say that this is an “implicit parameter”?
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
When is the value of this determined in a function; call time or definition time?
Call time
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);
}
};
Nothing at the time since it isn’t being called. Doesn’t exist.
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
‘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.