OOP Flashcards
What is a method?
A function which is a property of an object that can either be instance or static methods.
*Instance methods are built-in tasks performed by an object instance. Static methods are tasks called directly on an object constructor.
How can you tell the difference between a method definition and a method call?
A method definition uses the “function” keyword followed by a function code block that describes the method.
A method call uses the method name of its respective object followed by parenthesis and arguments (if any).
Describe method definition syntax (structure).
The property name and a colon followed by the function keyword, parameters (if any), and the function code block.
Describe method call syntax (structure).
The object name and method separated by the dot notation followed by parenthesis with arguments (if any).
How is a method different from any other function?
Methods can be accessed through its object. Normal functions can be accessed anywhere.
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods).
What are the four “principles” of Object-Oriented Programming?
Abstraction, Encapsulation, Inheritance, and Polymorphism.
What is “abstraction”?
The process of working with complex things in simple ways.
(i,e,. a light switch or automatic transmission.)
What does API stand for?
Application Programming Interface
What is the purpose of an API?
An API allows two or more computer programs to communicate with each other.
What is this in JavaScript?
This is a variable that its value is determined by when a function is called.
What does it mean to say that this is an “implicit parameter”?
Implicit parameters can be understood from something else without being explained.
When is the value of this determined in a function; call time or definition time?
The value is determined by when the functioned is called.
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);
}
};
This refers to nothing because the function is not called.
character.greet();
Given the above character object, what is the result of the following code snippet? Why?
The string, It’s-a-me-Mario! because the this keyword refers to what is left of the dot which is the character object that has the firstName property.