javascript-this Flashcards
What is this in JavaScript?
In JavaScript, the this keyword refers to an object. Which object depends on how this is being invoked (used or called). The this keyword refers to different objects depending on how it is used: In an object method, this refers to the object. Alone, this refers to the global object.
-https://www.w3schools.com/js/js_this.asp
What does it mean to say that this is an “implicit parameter”?
It means that its not specifically define, but is always available
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 object character
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
“It’s a-me !”
How can you tell what the value of this will be for a particular function or method definition?
We cannot tell
How can you tell what the value of this is for a particular function or method call?
Look to the left side of the dot to see what function is calling it