Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: final / immutable global variables?

Tags:

javascript

I think I know the answer but... is there any way to prevent a global variable from being modified by later-executing <script>? I know global variables are bad in the first place, but when necessary, is there a way to make it "final" or "immutable"? Hacks / creative solutions are welcome. Thanks

like image 781
jtgameover Avatar asked Mar 20 '09 02:03

jtgameover


2 Answers

the const keyword?

like image 169
Real Red. Avatar answered Sep 25 '22 21:09

Real Red.


I know this question is old, but you could use Object.freeze(yourGlobalObjectHere); I just wrote a blog post about it here.

like image 38
iambrandonn Avatar answered Sep 22 '22 21:09

iambrandonn