Suppose you work on a site with other developers. You create a function called "GetCookie". One of your collegues creates a function called the same thing, but it does something a little differently. So, your code collides.
With namespaced code you can define your function inside of a "package". This package has a namespace you provide... org.krstic.util.GetCookie. Because your code has a namespace, it's less likely to collide with someone else' code. This is how the world of Java, Python, Ruby, .Net, and other modern OO languages work. If you take a look at Dojo and YUI, you'll find that those libraries are namespaced. jQuery does not have to be namespaced...although, you can argue that it collides with other libraries that use the $() convenience selector. If you work on a site or product that has lots of javascript and multiple developers working on it, namespaces are a good thing. Rich On 11/16/06, Dragan Krstic <[EMAIL PROTECTED]> wrote:
unction package(ns) { > ns = ns.split('.'); > var cur = window, i; > while ( i = ns.shift() ) { > if ( !cur[i] ) cur[i] = {}; > cur = cur[i]; > } > > } > > For us, less expirienced, can someone explain this code? And what is benefit od namespaces? _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
_______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/