OOP Flashcards
(31 cards)
What is a method?
a function which is a property of an object
How can you tell the difference between a method definition and a method call?
method definition: declaring/defining. code is there but nothing happens
method call: DOT NOTATION
call the function to run the code
Describe method definition syntax (structure).
var objectName = { methodName: function(parameters) { code return result };
Describe method call syntax (structure).
ObjectName.methodName(parameters);
How is a method different from any other function?
it is the property of an object
IMPORTANT!
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
Polymorphism
What is “abstraction”?
being able to work with (possibly) complex things in simple ways.
ex/ light switch
ex/ car automatic transmission
What does API stand for?
application programming interface
What is the purpose of an API?
NUTSHELL: allows apps to disseminate or receive information between each other. interacting with an application to get or send info.
SIMPLE DEFINITION: an API delivers a user response to a system and sends the system’s response back to a user.
COMPLEX DEFITION: it is a set of functions that allows applications to access data and interact with external software components, operating systems, or microservices.
What is “this” in JavaScript?
reference to the lexical scope of the function at call time
What does it mean to say that this is an “implicit parameter”?
“this” parameter does not need to be explicitly defined
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); } };
character
How can you tell what the value of this will be for a particular function or method definition?
you can’t know for sure until it is called
How can you tell what the value of this is for a particular function or method call?
look left of the dot
that is typically the calling object
What kind of inheritance does the JavaScript programming language use?
prototype-based (or prototypal) inheritance.
JavaScript objects give certain behaviors (methods) or data (properties) to other objects.
What is a prototype in JavaScript?
an object with functionality that will be inherited down to any object connected to that prototype
original model on which something is patterned
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?
You can set prototypes
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
[[prototype]] chain
IMPORTANT
What does the “new” operator do?
create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
- creates blank object
- adds property/fxns to new object __proto__to link to fxn’s prototype object
- binds newly created object to “this” (“this” now referes to object created in step 1)
- returns “this” if fxn doesnt return an object. no need to put in “return” keyword
What property of JavaScript functions can store shared behavior for instances created with new?
.prototype property
What does the instanceof operator do?
SIMPLE: checks to see if variable was created from a specific constructor
COMPLEX: tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.
returns boolean
Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?
set timeout