Object Oriented Programming (OOP) Flashcards
What is a method?
a function stored in the property of an object
How can you tell the difference between method definitions and method calls?
method definition will always have the function keyword and a code block.
method call is always attached to an object.
Describe method call syntax:
object.method( )
How is a method different from any other function?
a method is a property of an object
What is the defining characteristic of object-oriented-programming (OOP)?
objects can contain both data and behavior(methods)
What are the four principles of object-oriented-programming?
Abstraction, Encapsulation, Inheritance, Polymorphism
What is “abstraction”?
being able to work with complex things in simple ways
What does API stand for?
Application Programming Interface
What is the purpose of an API?
communication between two softwares
What is this in JavaScript?
an implicit parameter of all JavaScript functions - the object that we’re working in
What does it mean to say that ‘this’ is an “implicit parameter”?
it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var
When is the value of this determined in a function? Call time or definition time?
call time - this does not exist/have value until the function is called
How can you tell what the value of this will be for a particular function or method definition 👀?
you cant - if a function is just being defined, this does not exist yet
How can you tell what the value of this is for a particular function or method call 👀?
check the object to the left of the dot
What kind of inheritance does the JavaScript programming language use?
prototype-based inheritance (prototypal inheritance)
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?
via inheritance from the prototype
If an object does not have its own property or method by a given key, where does JavaScript look for it?
inside the prototype object linked to the object. it goes up the prototype chain until it finds what it needs
What does the new operator do?
- creates a blank, plain JavaScript object.
- adds a property to the new object (__proto__) that links to the constructor function’s prototype object.
- binds the newly created object instance as the this context (all references to this in the constructor function now refer to the object created in first step)
- returns this
What property of JavaScript functions can store shared behavior for instances with new?
the prototype property
What does the instanceof operator do?
- tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.
- an instance is a created example of a thing
- example :
function Car(make, model, year) { this.make = make; this.model = model; this.year = year; } const auto = new Car('Honda', 'Accord', 1998);
console.log(auto instanceof Car); // expected output: true
What is a ‘callback’ function?
a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine/action.
Besides adding an eventListener callback function to an element or document, what is one way to delay the execution of a JavaScript function until some point in the future?
the setTimeout( ) global function
How can you set up a function to be called repeatedly without using a loop?
setInterval( )
What is the default time delay if you omit (leave out) the delay parameter from setTimeout( ) or setInterval( )?
0
What do setTimeout( ) and setInterval( ) return?
a timeoutId