Module 2 Flashcards
What is a method?
a function that is a property of an object
How can you tell the difference between a method definition and a method call?
the . call
Describe method definition syntax (structure).
__name of method__ : function(__parameters__) {
–code–
}
Describe method call syntax (structure).
__name of obj__ . __name of method__(__args__)
How is a method different from any other function?
it is a property of an object
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods); taking related data and functionality and putting them together in an object
What are the four “principles” of Object-Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
What is “abstraction”?
being able to work with complex things in a simple way (ex: light switch, auto transmition in a car, the DOM); a simple interphase that does complex things behind the scenes (ie pushing the gas/brake on a car vs thinking about how the engine delivers power to the wheels, etc)
What does API stand for?
application programming interface
What is the purpose of an API?
to connect computers/pieces of software to each other
What is this in JavaScript?
this is an implicit property of an object that refers to the object itself; when unassigned to an object this = Window object
What does it mean to say that this is an “implicit parameter”?
it is not explicitly defined (like a variable is), it ‘comes with’ the creation of the object; it is defined at the time of the method call
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 obj
How can you tell what the value of this will be for a particular function or method definition?
you cant; defined at call time
How can you tell what the value of this is for a particular function or method call?
find where the functionis called and look for the obj to the left of the dot
What kind of inheritance does the JavaScript programming language use?
prototype: objects inherit from other objects
What is a prototype in JavaScript?
an object that passes down properties
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?
prototypal inheritance from the global objs
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
its prototype
What does the new operator do?
creates an instance from a constructor function
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
What does the instanceof operator do?
checks the prototype tree of an object to see if something is there
What is a “callback” function?
a function that is used as an argument for another function