

Show HN: namespace.js - a 250 byte open source project. - mckoss
https://github.com/mckoss/namespace

======
mckoss
I wish there was more uniformity with the way JavaScript libraries manage the
global namespace. So, I stripped down the library I use to the bare
essentials, and made it a stand-alone open source (public domain) project.

I'm hoping that by removing the idiosyncrasies of my earlier version, I can
actually get others to adopt this mechanism.

Is it crazy to have such a tiny open source project?

(BTW: the gzipped/minified version of the library is less than 250 bytes -
hence the title).

~~~
reinhardt
Not crazy but probably an overkill. I'd just post it as a gist.

~~~
mckoss
Since I want this evangelize this to others, making a full repo lets me put in
a nice read me, make it clear the license is in the public domain, and also
provide unit tests.

------
pcwalton
Note that my colleague Dave Herman (on the TC39 committee; i.e. the JavaScript
standards committee) is working on an official modules proposal for the next
version of JavaScript, code-named Harmony. See here for examples:
[http://wiki.ecmascript.org/doku.php?id=strawman:simple_modul...](http://wiki.ecmascript.org/doku.php?id=strawman:simple_modules_examples)

------
calebmpeterson
I like it for how single-minded it is. Do one thing and do it well.

Here's my one question (and it's not specific to namespace.js)

How to do imports so I can avoid

var obj = new namespace.com.foo.bar.baz.FooBar(...);

~~~
mckoss
I will generally have an "imports" type line at the top of my module, and then
use the abbreviated name in the code. This is similar to Python's "from module
import name" pattern.

    
    
        var library = namespace.com.foo.bar.baz;
        ...
        var obj = new library.FooBar();
    

It's generally considered a best practice (in the Python community) to leave
the external module name (like "library", above) so that someone reading your
code can recognize which functions are external to your module, and which ones
are local.

~~~
calebmpeterson
Thanks for the input!

------
mckoss
Update: I added a project web site with a FAQ here:

<http://mckoss.github.com/namespace/>

