Object-Oriented Programming Flashcards
What is a method?
a method is a function which is a property of an object
How can you tell the difference between a method definition and a method call?
method call does not have a code block
Describe method definition syntax (structure).
method: function( ) { }
Describe method call syntax (structure).
Object.method( )
How is a method different from any other function?
method is associated with object, function is not
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”?
simplifying complex behavior
What does API stand for?
application programming interface
What is the purpose of an API?
connects computers and programs to each other
What is ‘this’ in JavaScript?
implicit parameter of all JavaScript functions
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
When is the value of this determined in a function; call time or definition time?
call
How can you tell what the value of this will be for a particular function or method definition?
you can’t
How can you tell what the value of this is for a particular function or method call?
the object to the left of the dot
What kind of inheritance does the JavaScript programming language use?
prototype-based or prototypal
What is a prototype in JavaScript?
the mechanism by which JavaScript objects inherit features from one another
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?
they come with built in prototype objects
If an object does not have its own property or method by a given key, where does JavaScript look for it?
on the prototypes
What does the new operator do?
- create an instance of a user-defined object type
- 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
- returns this if the function doesn’t return an object
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
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.