JS and Object-Oriented Programming Flashcards
What is a method?
A function which is a property of an object.
How is a method different from any other function?
It is associated with an object
What is the defining characteristic of Object-Oriented Programming?
Related method and variables are bundled together in objects - a program is the interaction of the objects with each other
What are the four “principles” of Object-Oriented Programming?
- Abstraction
- Encapsulation
- Inheritance
- polymorphism
What is “abstraction”?
being able to work with (possibly) complex things in simple ways.
also: hiding/abstracting away the details of how something is implemented to make working with it easier
What does API stand for?
application programming interface
What is the purpose of an API?
An API allows programs/objects to interact with other programs/objects and controls what can be accessed or modified.
What is the keyword ‘this’ in JavaScript?
A reference to the object that a method/function is related to/associated with;
What does it mean to say that ‘this’ is an “implicit parameter”?
It means that even if ‘this’ isn’t listed as a parameter in the function/method definition, it is still defined and available to use inside the function/method
When is the value of ‘this’ determined in a function; call time or definition time?
Call-time;
How can you tell what the value of ‘this’ will be for a particular function or method definition?
You can’t. The value of this is determined at call time (it is a call-time binding)
How can you tell what the value of ‘this’ is for a particular function or method call?
Look at how/where the function/method is being called
– also check left of the dot
What kind of inheritance does the JavaScript programming language use?
Prototypal inheritance / prototype-based inheritance
What is a prototype in JavaScript?
a JavaScript prototype is an object that contains properties and 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 objects, arrays, and numbers?
The methods have been inherited through prototypal inheritance