Object-oriented programming Flashcards
What is a method?
A method is a function which is a property of an object.
In JavaScript functions themselves are objects, so, in that context, a method is actually an object reference to a function.
How can you tell the difference between a method definition and a method call?
o Method definitions will always have a function keyword and a code block
o Method calls start with an object name and has arguments that are being passed
Describe method definition syntax (structure).
propertyName: functionName( ) {
Return ‘anything’;
}
Describe method call syntax (structure).
objectName.method( )
How is a method different from any other function?
They are functions stored in an object
What is the defining characteristic of Object-Oriented Programming?
Objects can contain both:
- Data (as properties)
- Behavior (as methods)
What are the four “principles” of Object-Oriented Programming?
o Abstraction
o Encapsulation
o Inheritance
o Polymorphism
What is “abstraction”?
Being able to work with (possibly) complex things in simple ways (such as, turning a light on/off)
What does API stand for?
Application Programming Interface
What is the purpose of an API?
Give programmers a way to interact with a system(s) in a simplified, consistent fashion (aka abstraction) without knowing about how they all work independently.
What is ‘this’ in JavaScript?
The object that you’re working within
What does it mean to say that this is an “implicit parameter”?
The parameter is available (in a function’s code block) even though it was never included in the function’s parameter list OR declared in a var
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); } };
Undefined (there is nothing in front of greet)
Given this character object:
var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } };
What is the result of the following code snippet? Why?
character.greet();
It’s a me, Mario! Because greet is being called on the character object