Is there a "concise" way to do namespacing in JavaScript?
Posted
by
olliej
on Stack Overflow
See other posts from Stack Overflow
or by olliej
Published on 2008-08-16T05:57:37Z
Indexed on
2012/03/23
23:29 UTC
Read the original article
Hit count: 154
JavaScript
|namespaces
I've frequently encountered sites that put all of their javascript inside a "namespace" structure along the lines of
namespaces = { com : { example: { example.com's data} }
But setting this up safely with respect to other namespaced frameworks seems to require a relatively hefty amount of code (defined as > 2 lines). I was wondering whether anyone knows of a concise way to do this? and whether there's a relatively standard/consistent way to structure it? eg. is the "com" namespace directly attached to the global object, or is it attached through a namespace object?
[Edit: whoops, obviously {com = { ... } }
wouldn't accomplish anything close to what i intended, thanks to Shog9 for pointing that out. :D]
© Stack Overflow or respective owner