Week 5 Quiz Questions 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 required an object to be associated with it. method definition is within an object, function keyword, etc.
Describe method definition syntax (structure).
var object = {methodName: function (param) {code block}};
Describe method call syntax (structure).
object.methodName(argument)
How is a method different from any other function?
methods are directly related to the object they are associated with
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?
a way for two or more computer programs to communicate with each other.
What is this in JavaScript?
this is referring to calling object
What does it mean to say that this is an “implicit parameter”?
it is available in the function code block even though it wasnt included in the function definition or declared with var
When is the value of this determined in a function; call time or definition time?
on function call
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);
}
};
this refers to the character object– character.firstName
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
‘It’s-a-me, Mario!”
‘this’ in .greet is directly referring to ‘character’
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
its a me undefined
‘this’ is now referring to the window object