OOP Flashcards
What is a method?
A method is a function which is a property of an object. There are two kinds of methods: instance methods which are built-in tasks performed by an object instance, or static methods which are tasks that are called directly on an object constructor.
How can you tell the difference between a method definition and a method call?
defining - has a function code block
calling - has arguments
Describe method definition syntax (structure).
-property name:
-function definition(parameters)
code block
Describe method call syntax (structure).
object.method(arguments)
doggo.bork()
How is a method different from any other function?
The difference is that a method is associated with an object, while a function is not.
if there is a dot - method
no dot - function
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods) that work together
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
What does API stand for?
application programming interface
What is the purpose of an API?
way for two or more computer programs to communicate with each other
What is this in JavaScript?
it’s an implicit parameter,
What does it mean to say that this is an “implicit parameter”?
meaning that 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
How can you tell what the value of this will be for a particular function or method definition?
if only definition - can’t
How can you tell what the value of this is for a particular function or method call?
Find where the function is called and look for an object to the left of the dot
(if no dot, this = window)
What kind of inheritance does the JavaScript programming language use?
prototype based
prototypal
What is a prototype in JavaScript?
source for shared behavior/data
sort of like a toolbox with all the tools
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?
within the prototype object
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
prototype
What does the new operator do?
- makes a blank javascript object
- takes value of the prototype property and sets it
- turns new object into this (in the code block)
4.
What property of JavaScript functions can store shared behavior for instances created with new?
.prototype
What does the instanceof operator do?
The instanceof operator 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.
we are created instances of ‘human’
What is a “callback” function?
function you call inside another function
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?
setTimeout()
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 the delay parameter from setTimeout() or setInterval()?
If this parameter is omitted, a value of 0 is used, meaning execute “immediately”, or more accurately, the next event cycle.
What do setTimeout() and setInterval() return?
timeoutID / intervalID