js this basics Flashcards
What is this in JavaScript?
object that represents the lexical scope of the reference at call time
What does it mean to say that this is an “implicit parameter”?
it is a parameter that exists even though it is not explicitly defined
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();
‘It’s-a-me Mario!’
this.character inside the method returns character 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’
this.firstName is undefined
How can you tell what the value of this will be for a particular function or method definition?
you cannot unless you know when and where this is
How can you tell what the value of this is for a particular function or method call?
check the lexical scope?