JavaScript-this Flashcards
What is “this” in JavaScript
It’s an implicit parameter that references the object that is executing the current function
What does it mean to say that “this” is an “implicit parameter”?
It is available in a function’s code block even though ti 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?
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): )};
The value of the firstName property in the object, character.
Given the above character object, what is the result of the following code snippet? Why? character.greet( );
“It’s-a-me, Mario!” because it’s within the object.
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?
The object to the left of the dot
How can you tell what the value of this is for a particular function or method call?
I don’t know.