m-2-0522 Flashcards
(135 cards)
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 definition is found inside the declaration of an object
method call is done by using name of the object followed by a period and the name of the method
Describe method definition syntax (structure).
var object = { method: function () { } };
Describe method call syntax (structure).
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?
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
What does API stand for?
application programming interface
What is the purpose of an API?
to give programmers a way to interact with a system in a simplified, consistent fashion
What is this in JavaScript?
the value of this is determined by how a function is called
this describes the current context you’re in
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?
the value of this is determined when the function is called
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); } };
window object
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
It’s-a-me, Mario!
Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
It’s-a-me, undefined!
How can you tell what the value of this will be for a particular function or method definition?
we 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
What kind of inheritance does the JavaScript programming language use?
prototype-based (or prototypal) inheritance
What is a prototype in JavaScript?
a JavaScript prototype is simply 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?
prototype-based inheritance
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
prototype object
What does the new operator do?
The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property