OOP Flashcards
What is amethod?
A function that is a property of an object
How can you tell the difference between a methoddefinitionand a methodcall?
Method definition is a shorter syntax for defining a function property in an object initializer.
Method call has an argument
Describe methoddefinitionsyntax (structure).
Var object = {
method() {
return ‘something’
}
};
Describe methodcallsyntax (structure).
methodName(argument);
How is a method different from any other function?
A method is associated with an object, while a function is not
Usually a method is group with other similar properties
What is thedefining characteristicof Object-Oriented Programming?
It stores data in objects to create better structured and reusable code
What are the four “principles” of Object-Oriented Programming?
Abstraction, Encapsulation, Inheritance, Polymorphism
What is “abstraction”?
The idea of breaking down something that is complex into simpler terms
What does API stand for?
Application Programming Interface
What is the purpose of an API?
To allow two or more programs to communicate with each other
What isthisin JavaScript?
“This” is the object that a method called with
What does it mean to say thatthisis an “implicit parameter”?
It is available in the code block even through it was never included in the function’s definition
Whenis the value ofthisdetermined in a function;call timeordefinition time?
The value of “this” is determined when the function is called
How can you tell what the value ofthiswill be for a particular function or methoddefinition?
You can’t tell?
How can you tell what the value ofthisis for a particular function or methodcall?
look at the object name to the left of the dot
What kind of inheritance does the JavaScript programming language use?
Prototypal inheritance (objects inherit from other objects)
What is a prototype in JavaScript?
an object that contains properties and (predominantly) methods that can be used by other objects.
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?
The methods are defined on a prototype object and those methods are borrowed as needed
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
In the objects prototype chain
It will go down prototype chain until it runs out of things to look at
If there’s nothing, it returns undefined
What does thenewoperator do?
It creates an instance of a user defined object or one of the constructor objects
What property of JavaScript functions can store shared behavior for instances created withnew?
AFunctionobject’sprototypeproperty is used when the function is used as a constructor with thenewoperator.