jQuery.package = function(ns, obj) {
   ns = ns.split('.');
   var cur = window, i;
   while ( i = ns.shift() )
      cur = cur[i] || ( cur[i] = {} );
   if ( obj )
      jQuery.extend(cur, obj);
};

$.package('example.ns', {
   example: function(){
      // Some stuff...
   }
});

On 11/20/06, Alan Gutierrez <[EMAIL PROTECTED]> wrote:
> * Aaron Heimlich <[EMAIL PROTECTED]> [2006-11-16 20:23]:
> > This function simply automates the process of creating a namespace. So I
> > could do
> >
> > package("really.long.namespace");
> > really.long.namespace.debug = function(info) {
> >    // do stuff
> > }
>
> When you have really long namespaces, you can make life a lot easier
> with namespace aliases...
>
> function foo() {
>    var debug = really.long.namepsace.debug
>    debug("Foo!")
>    debug("Bar!")
>    debug("Baz!")
> }
>
> Just so you know. Namespaces do necessarily mean a lot of extra
> typing, just a lot fewer collisions and more reuse.
>
> (As always, correct me if I'm wrong, it's been a while.)
>
> --
> Alan Gutierrez - 504 717 1428 - [EMAIL PROTECTED] - http://blogometer.com/
>                Think New Orleans - http://thinknola.com/
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to