Yah, as Ian mentioned, you lose all type checking with this technique. Also, you require that the object be in the global name space, while a singleton class does not clutter up the global namespace at all (var globalData = AppState.getInstance(); globalData.foo = "bar"). Finally, how do you alert other parts of the application to a change in a property? Setters and getters can do that for you automatically by broadcasting an event, but an anonymous object can't do that, you have to trigger the event yourself when you change the property.

Not understanding why something is done in a particular way does not make it "lame".

Nathan
http://www.nathanderksen.com


On Jan 31, 2006, at 3:08 PM, Steven Sacks wrote:

Making a class for globals is lame. I don't get why people do stuff like
that.  It's completely unnecessary.  Here's how I make a namespace for
globals in one line.

On frame one of the root timeline:

_global.APP = {};

Wow. That was so hard.

APP.someglobal
APP.someotherglobal
APP.etc



Nathan Derksen nderksen at sfu.ca wrote:
I generally keep at least one singleton class which is responsible
for storing global properties. I make those properties accessible
with getters and setters so that I can allow changes in those
properties to trigger events. You can't really do that if you use
_global to store your data. Also, there is always a risk in name
space collision if you load in other elements that also use global,
where one or more variables use the same name and are thus
inadvertently shared for different uses. You definitely do not want
to use _global within any classes that you create, as that
can cause
entanglement, gives you no private protection, and does not
properly
contain your code into a well-defined unit with a well-defined API.

Nathan
http://www.nathanderksen.com

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to