This method basically allows you to use "Local" object to store functions local values and "Static" object to store functions static values!
To create the functions "Static" objects, use unique global variable names based on the function name itself such as "Function_Test_Function", "Function_ScreenGet_Function", "Function_Calculate8776_Function", "Class_Function_Test_Class", etc, etc, etc ...!
When a function returns, javascript automatically clears all its "Local" variables values!
If
you need a value to be remembered between the function calls, you need
to store that value in a "Static" variable of that same function!
Unfortunately, javascript does not support functions "Static" variables! (Most languages that I know support it!)
So, an alternative is:
- lets say your function name is "Test"
- inside the function, create a "global" object based on your function's name, example: "Function_Test_Function"
-
inside the function, declare "Static" variable as local object by
passing the reference of "Function_Test_Function" object inside it!
-
now you can store static values of your function through the local
"Static" object, example: Static.x, Static.y, Static.data, etc, etc
note that:
- using "Static.x" or "Function_Test_Function.x" is the same thing, but the former is more practical to use then the latter!
- both "Static" or "Function_Test_Function" variables reference the same object stored in the ram memory!
-
"Static" or "Function_Test_Function" variables don't contain the
object's values, they contain only a reference to an object stored in
the memory!
Keywords:
JavaScript - Alternative for Functions Static Variables!
- Alcatel (6)
- Android (6)
- Blogger (10)
- Calculators (1)
- Facebook (1)
- Games (4)
- GitHub (1)
- Html-Css-Js (44)
- Illustrator (2)
- InfoSec (13)
- Photoshop (4)
- PHP (11)
- Unicode (2)
- Windows (2)
jQuery
elevateZoom (Requires jQuery)
Facebook Messenger (Donation)
Many donors of this blog prefer to donate their money through Facebook Messenger!
Click here to go to this blog's Facebook Page!
Thank you!
Click here to go to this blog's Facebook Page!
Thank you!
Request Web\PHP\JavaScript\HTML Project !
Contact us if you want us to develop a Web\PHP\JavaScript\HTML project for you!
Advertise On This Blog!
If you want a Product\Service\Event to be advertised on this blog, feel free to contact us!
ADS - Multi One Password
Ads (Reserved)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment