JS- this Flashcards
What is this in JavaScript?
an implicit parameter, reference to the object that is executing the current function
What does it mean to say that this is an “implicit parameter”?
not explicitly defined but understood
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); } };
there is no this, because the greet method is not being called so NOTHING, NONEXISTENT
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
“it’s-a-me, Mario!” the greet method of the character object is being called
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” because the hello variable is a property of the window object
How can you tell what the value of this will be for a particular function or method definition?
you can’t know in a definition, only exists in a call
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