Javascript-this Flashcards
What is this in JavaScript?
- implicit parameter –> this is pointing to an object we want to look at.
key word that contains a value defined at a call time.
What does it mean to say that this is an “implicit parameter”?
- value that is available in function defintion even though we didn’t put it in a parameter
- NOT explicitly written in function definition. and it is available in function definition.
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?
There is not definition because we are not in call yet, only in defition time
referring to character object.
Given the above character object, what is the result of the following code snippet? Why?
The result will be the string value Its me mario. we are calling from character.
Given the above character object, what is the result of the following code snippet? Why?
undefined! because window doesn’t have an object!
this is not gear towards to character anymore.
How can you tell what the value of this will be for a particular function or method definition?
You wouldn’t be able to tell because function is not called yet.
by default it will refer to the default object.
How can you tell what the value of this is for a particular function or method call?
you look at the object that is on the left