[thelist] JS: global vars...

Tom Dell'Aringa pixelmech at yahoo.com
Tue Sep 2 12:50:37 CDT 2003


Greets,

I've been working on this monster of an app where I am dealing with
quite of bit of data on a page - roughly 20 kinds of data say on one
page with all different kinds of values. So you can imagine I have a
whole library of functions to deal with the data.

Quite often I have a case where one function knows about some piece
of information that another function must access, yet they cannot
talk directly - I can't send it as a parameter.

In these cases I have been using the (sometimes called evil) global
variable. That way the 2nd function can read the data it needs.

So! My question is what are the cons of this approach? The bonus is
that it makes it very easy for me to read/write the values.

Second, what are the alternatives? Should I be encapsulating such
data in objects? This of course would take a bit more development
time but might be a better solution.

Looking forward to thoughts...

Tom

=====
http://www.pixelmech.com/ :: Web Development Services
http://www.DMXzone.com/ :: Premium Content Author / JavaScript / Every Friday!
http://www.maccaws.com/ :: Group Leader
[Making A Commercial Case for Adopting Web Standards]

"That's not art, that's just annoying." -- Squidward


More information about the thelist mailing list