Thanks for the reference.  My scheme is a variant of "nested object
namespacing".    I disagree with the author's arguments that this is
"overly complex" to avoid unintentional collisions.
As we write larger JavaScript packages and systems, there can be a
really large number of names in the system.  Putting them all in a top-
level namespace is just asking for trouble
in the long run, I think.

I personally despise GUID-based naming (as was using in Microsoft OLE,
e.g.) - but the 'reverse domain' approach ('org.startpad.format')
allows for simplicity of naming as well as
a simple guarantee of uniqueness.

I would agree that my current implementation of namespace.lookup() is
not speed-optimized - it does split and walk the link chain, even if
the item has been created.  Note though,
that you can option use the expression "namespace.org.startpad.format"
instead of the function call "namespace.lookup('org.startpad.format')"
IFF you are sure that the namespace
has already been loaded.

In my standard use, namespace.lookup() is only called when modules are
being loaded - i.e., not very often - since external namespace object
value are cached in local variables of
each namespace closure.

On Jan 19, 3:59 pm, Balázs Galambosi <[email protected]> wrote:
> 2011/1/19 mckoss <[email protected]>:
>
> > I've been using a namespace pattern I developed and would love to get
> > feedback on my implementation/design.  I know there is some wheel re-
> > invention here - I just have not yet found other patterns I like as
> > well.
>
> There may be a reason for that.
>
> > My goals were to create something that felt very close to python
> > modules, and be natural in the JavaScript world. [examples]
>
> This is where the problem starts.
>
> The main issue here is that even the word namespace creates a false
> illusion, that Javascript can be treated similar to other languages.
>
> The hierarchically construction is quite appealing I can't argue that,
> but it's very inefficent to use deeply nested chains of objects. They
> come with a cost because of the way they work (property lookups).
>
> The biggest problem here isn't the tools/libraries, but the people who
> tend to misuse them.
>
> Recommended reading:http://peter.michaux.ca/articles/javascript-namespacing
>
> - Balázs

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to