Hi people!
I'm really trying to find out this information on the internet, but I can't find it.
Since the keyword "this" let me access a property of a function outside of it, I want to know if the garbage collector behaves the same way as it behaves with global variables.
So far as I know, javascript free the memory when an object or variable lost its reference.
So in case of this keyword being used constantly, it behaves like a local variable that can be accessed outside the function? Or its behaves like a global variable(but not being global or local variable)?
My concern is performance.
So it's best for me to use this to change the property of a sprite for example:
this.carSprite.opacity = 100;
Or it's best for me to make a function that returns the opacity?
Function carSpriteOpacity(){
return 100;
}
Here is an example of information that tells me to use the "this" keyword to avoid using global variables.
But what confuses me is it's saying that it is different from the global variable, but it also can be accessed like a global variable outside of the function. So what I'm missing here?

I'm really trying to find out this information on the internet, but I can't find it.
Since the keyword "this" let me access a property of a function outside of it, I want to know if the garbage collector behaves the same way as it behaves with global variables.
So far as I know, javascript free the memory when an object or variable lost its reference.
So in case of this keyword being used constantly, it behaves like a local variable that can be accessed outside the function? Or its behaves like a global variable(but not being global or local variable)?
My concern is performance.
So it's best for me to use this to change the property of a sprite for example:
this.carSprite.opacity = 100;
Or it's best for me to make a function that returns the opacity?
Function carSpriteOpacity(){
return 100;
}
Here is an example of information that tells me to use the "this" keyword to avoid using global variables.
But what confuses me is it's saying that it is different from the global variable, but it also can be accessed like a global variable outside of the function. So what I'm missing here?
