Preserved forum archive. This topic stores the original first post and locally mirrored RPG Maker Web attachments when available. It is posted by the BMMPlay archive account, not by the original creator.
Original Source
- Original title: Garbage Collector: this vs global Variables
- Original author: Eliaquim
- Original date: January 19, 2020
- Source thread: https://forums.rpgmakerweb.com/threads/garbage-collector-this-vs-global-variables.117429/
- Source forum path: Game Development Engines > RPG Maker Javascript Plugins > Learning Javascript
Summary
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.
Archived First Post
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?
Protected download
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?
Protected download
Downloads / Referenced Files
Log in to download
Log in, then follow the RPG Maker Developers Group to see these download links.
Log in to downloadReferenced Images / Attachments
Creator Claims / Removal
If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.
Replies (0)
No replies yet.
0
replies
1
view
Topic Summary
Loading summary...
