Global Variables Are Evil
I have been known to tell people in an enterprise environment to avoid global functions and variables in JavaScript at all costs. My reasons are purely from a maintenance point of view: it’s easier to document variables attached to classes or namespaces and it’s easier to debug (because you know where to find the variable/function in question). Turns out that Douglas Crockford agrees with me in his latest post, Global Domination.
It’s so much easier to argue things successfully when you can find others to back up your point of view.
Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.
Both comments and pings are currently closed.




One Comment
Read Code Complete 2nd Ed. [Steve McConnell]. Chapter 13.3 is entirely on Global Data. The entire text focuses on good programming techniques and frequently touches on the need to avoid Globals. Although reading through the 900+ pages may daunting, you’ll finish as an enlightened professional, you’ll be surprised at how many of today’s issues (in the computing realm) have been around for decades.
Adam Kahtava on June 5th, 2006 at 10:38 pm
Comments are automatically closed after 14 days.