Namespace.js

Following my previous article on object oriented programming in Javascript, I released yesterday a small script which allows you to manage namespaces. I know that solutions already exist. Not considering the one from libraries (I wanted a library independent script), I was not satisfied by any of them.

Namespace.js is very simple to use. It contains all common actions encountered when dealing with namespaces. It can import objects in the global scope or include remote scripts based on their namespace. It is very small (5.4 Kb minified), open source and of course library independent.

I published the project on google code at http://code.google.com/p/namespacedotjs

Here are some examples:

Namespace('foo.bar');
foo.bar.myFunction = function() {};
 
Namespace('com.example', {
   MyClass: function() { return {}; }
});
var obj = new com.example.MyClass();
 
Namespace.use('com.example.MyClass');
var obj2 = new MyClass();
 
// include com/example/RemoteClass.js
Namespace.include('com.example.RemoteClass');
var obj3 = new com.example.RemoteClass();
 
Namespace.registerNativeExtensions();
'com.foo.bar'.namespace();
Share:
  • DZone
  • Digg
  • del.icio.us
  • Technorati
  • StumbleUpon
  • TwitThis
  • Reddit
  • Facebook
  • LinkedIn
  • email
  • Google Bookmarks
  • Identi.ca
  • MySpace
  • Netvibes
  • Slashdot
  • Wikio
  • Yahoo! Buzz
  • HackerNews
  • Posterous
  • Tumblr
Posted in Unclassified at February 26th, 2009. Trackback URI: trackback
  • Observer
    Thanks. Great work. It's good to see interest and new approaches in this area. Keep it up.
  • maximebf
    You're right and I'm sorry. The thing is I forgot where I read it. But I should have made some research. I'm completely for citing all sources, so my bad. I will add the link in the sources.
  • Observer
    @Maxime

    Your library looks interesting but I found it disappointing that you neglected to credit the sources that appear to have directly influenced your work; especially since you state that you're aware of prior implementations.

    Your "com.foo.bar".namepsace(); is a direct re-implementation of a proposal made by Juriy Zaytsev (kangax) back in January of 2008 here:

    http://thinkweb2.com/projects/prototype/namespa...

    Is crediting prior work that painful or hard or was this just an oversight?
  • I checked out the source on Google Code. The script definitely looks interesting and useful.

    I've been using YUI pretty exclusively on projects, therefore make use of the YUI Loader Utility. There are times when I'm using both the Google Ajax JS libraries and YUI; both of these libraries have their own script loaders; but something like this utility would be useful to load each of the library's seed files.

    I'll report back when I get around to testing it out more...
blog comments powered by Disqus