<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Namespaces in jQuery</title>
	<atom:link href="http://bililite.com/blog/2008/08/05/namespaces-in-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/</link>
	<description>Thoughts on web design and programming from a very occasional volunteer webmaster</description>
	<lastBuildDate>Thu, 22 Jul 2010 22:04:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Danny</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-903</link>
		<dc:creator>Danny</dc:creator>
		<pubDate>Mon, 02 Nov 2009 16:12:31 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-903</guid>
		<description>@Shabeer Naha:
Your code works, but the idea of namespacing is a little different. After changing the namespace, all the methods that are not overridden still exist, and the new methods continue to be visible in the chain. Thus:
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$(&#039;p&#039;).danny().text(&#039;Hello&#039;).foo().bar().fadeOut();&lt;/code&gt;&lt;/pre&gt;

Your code would require
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$(&#039;p&#039;).text(&#039;Hello&#039;).danny().foo().danny().bar().fadeOut();&lt;/code&gt;&lt;/pre&gt;

Not a huge difference, but a conceptual one.
--Danny</description>
		<content:encoded><![CDATA[<p>@Shabeer Naha:<br />
Your code works, but the idea of namespacing is a little different. After changing the namespace, all the methods that are not overridden still exist, and the new methods continue to be visible in the chain. Thus:</p>
<pre><code class="language-javascript">$('p').danny().text('Hello').foo().bar().fadeOut();</code></pre>
<p>Your code would require</p>
<pre><code class="language-javascript">$('p').text('Hello').danny().foo().danny().bar().fadeOut();</code></pre>
<p>Not a huge difference, but a conceptual one.<br />
&#8211;Danny</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shabeer Naha</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-901</link>
		<dc:creator>Shabeer Naha</dc:creator>
		<pubDate>Mon, 02 Nov 2009 13:12:47 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-901</guid>
		<description>Isnt it much easier if it were done like this  :
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;(function($) {
    $.fn.danny = function (){
        var jq = this;
        return {
            foo: function(){
                return jq.each(function(){});
            },

            bar: function(){
                return jq.each(function(){});
           }
       }
    };
})(jQuery);

(function($) {
    $.fn.danny2 = function (){
        var jq = this;
        return {
            foo: function(){
                return jq.each(function(){});
            },

            bar: function(){
                return jq.each(function(){});
           }
       }
    };
})(jQuery);

$(&#039;p&#039;).danny().foo();
$(&#039;p&#039;).danny2().foo();

$(&#039;p&#039;).danny().bar();
$(&#039;p&#039;).danny2().bar();&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Isnt it much easier if it were done like this  :</p>
<pre><code class="language-javascript">(function($) {
    $.fn.danny = function (){
        var jq = this;
        return {
            foo: function(){
                return jq.each(function(){});
            },

            bar: function(){
                return jq.each(function(){});
           }
       }
    };
})(jQuery);

(function($) {
    $.fn.danny2 = function (){
        var jq = this;
        return {
            foo: function(){
                return jq.each(function(){});
            },

            bar: function(){
                return jq.each(function(){});
           }
       }
    };
})(jQuery);

$('p').danny().foo();
$('p').danny2().foo();

$('p').danny().bar();
$('p').danny2().bar();</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Teo</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-894</link>
		<dc:creator>Teo</dc:creator>
		<pubDate>Fri, 30 Oct 2009 13:37:07 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-894</guid>
		<description>Thanks! I am new to JavaScript and jQuery but this proved to be very useful for creating a small framework of plugins for my company.</description>
		<content:encoded><![CDATA[<p>Thanks! I am new to JavaScript and jQuery but this proved to be very useful for creating a small framework of plugins for my company.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-681</link>
		<dc:creator>Danny</dc:creator>
		<pubDate>Tue, 21 Jul 2009 08:24:28 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-681</guid>
		<description>@Jeff:
Yes, Ariel Flesler&#039;s code is very similar to mine under the hood, though he doesn&#039;t use __proto__
Danny</description>
		<content:encoded><![CDATA[<p>@Jeff:<br />
Yes, Ariel Flesler&#8217;s code is very similar to mine under the hood, though he doesn&#8217;t use __proto__<br />
Danny</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-680</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Mon, 20 Jul 2009 19:01:07 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-680</guid>
		<description>@Danny
I agree. As much I like the syntax it produces I don&#039;t believe I trust it enough to use it.
FYI, I&#039;ve come across a couple other attempts to do jQuery namespacing.

Ariel Flesler:
http://flesler.blogspot.com/2008/04/jquerymodularize.html

John Resig:
http://dev.jquery.com/~john/plugins/space/

Flesler&#039;s code produces results similar to yours. Resig&#039;s code produces results similar to Saraiva&#039;s, though chaining doesn&#039;t seem to work.

Thanks and keep up the good work.</description>
		<content:encoded><![CDATA[<p>@Danny<br />
I agree. As much I like the syntax it produces I don&#8217;t believe I trust it enough to use it.<br />
FYI, I&#8217;ve come across a couple other attempts to do jQuery namespacing.</p>
<p>Ariel Flesler:<br />
<a href="http://flesler.blogspot.com/2008/04/jquerymodularize.html" rel="nofollow">http://flesler.blogspot.com/2008/04/jquerymodularize.html</a></p>
<p>John Resig:<br />
<a href="http://dev.jquery.com/~john/plugins/space/" rel="nofollow">http://dev.jquery.com/~john/plugins/space/</a></p>
<p>Flesler&#8217;s code produces results similar to yours. Resig&#8217;s code produces results similar to Saraiva&#8217;s, though chaining doesn&#8217;t seem to work.</p>
<p>Thanks and keep up the good work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-679</link>
		<dc:creator>Danny</dc:creator>
		<pubDate>Mon, 20 Jul 2009 17:49:27 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-679</guid>
		<description>I agree that the syntax is nice without the extra parentheses but it&#039;s the only way to actually return an object that depends on its context (i.e. pass &quot;&lt;code&gt;this&lt;/code&gt;&quot; to it). Saraiva works around that by creating, effectively, a global variable (jQuery.fn.curReturn) that stores the last jQuery object created. I think that will get you into trouble with any complex manipulations as one $() overwrites the previous one.</description>
		<content:encoded><![CDATA[<p>I agree that the syntax is nice without the extra parentheses but it&#8217;s the only way to actually return an object that depends on its context (i.e. pass &#8220;<code>this</code>&#8221; to it). Saraiva works around that by creating, effectively, a global variable (jQuery.fn.curReturn) that stores the last jQuery object created. I think that will get you into trouble with any complex manipulations as one $() overwrites the previous one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-676</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Mon, 20 Jul 2009 13:52:05 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-676</guid>
		<description>@Danny
I actually like the syntax that results from this code:
http://projects.pro.br/gsaraiva/jquerynamespace/

$(&#039;p&#039;).danny.foo()
$(&#039;p&#039;).danny2.foo()
$(&#039;p&#039;).danny.foo().danny2.foo()

as opposed to

$(&#039;p&#039;).danny().foo()
$(&#039;p&#039;).danny2().foo()
$(&#039;p&#039;).danny().foo().danny2().foo()

However I think the code lacks elegance and flexibility relative to yours. A merger of the two would be my ideal.</description>
		<content:encoded><![CDATA[<p>@Danny<br />
I actually like the syntax that results from this code:<br />
<a href="http://projects.pro.br/gsaraiva/jquerynamespace/" rel="nofollow">http://projects.pro.br/gsaraiva/jquerynamespace/</a></p>
<p>$(&#8216;p&#8217;).danny.foo()<br />
$(&#8216;p&#8217;).danny2.foo()<br />
$(&#8216;p&#8217;).danny.foo().danny2.foo()</p>
<p>as opposed to</p>
<p>$(&#8216;p&#8217;).danny().foo()<br />
$(&#8216;p&#8217;).danny2().foo()<br />
$(&#8216;p&#8217;).danny().foo().danny2().foo()</p>
<p>However I think the code lacks elegance and flexibility relative to yours. A merger of the two would be my ideal.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony Rodriguez</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-493</link>
		<dc:creator>Anthony Rodriguez</dc:creator>
		<pubDate>Thu, 12 Mar 2009 16:36:53 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-493</guid>
		<description></description>
		<content:encoded><![CDATA[<p>@danny</p>
<p>Coming from a java background, I did feel that the $.draggable(’option’, whatever) syntax was a little awkward.  I just started working with jQuery and I wanted to find the &#8220;jQuery way&#8221; to namespace as I have been doing in plain old javascript up until now.  Great blog. Keep up the good work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-492</link>
		<dc:creator>Danny</dc:creator>
		<pubDate>Thu, 12 Mar 2009 16:08:45 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-492</guid>
		<description>@anonymous:
Looks cool. I&#039;ve been using jQuery UI widgets as the basis for a few of my plugins, and I&#039;d like to get them to use plugin namespaces, and this would allow something like $(selector).ui().draggable().option(whatever), rather than $.draggable(&#039;option&#039;, whatever).
--Danny</description>
		<content:encoded><![CDATA[<p>@anonymous:<br />
Looks cool. I&#8217;ve been using jQuery UI widgets as the basis for a few of my plugins, and I&#8217;d like to get them to use plugin namespaces, and this would allow something like $(selector).ui().draggable().option(whatever), rather than $.draggable(&#8216;option&#8217;, whatever).<br />
&#8211;Danny</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://bililite.com/blog/2008/08/05/namespaces-in-jquery/comment-page-1/#comment-491</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Thu, 12 Mar 2009 00:10:15 +0000</pubDate>
		<guid isPermaLink="false">http://bililite.com/blog/index.php/2008/08/05/namespaces-in-jquery/#comment-491</guid>
		<description>I reworked your code a bit to allow for chained namespacing (like in java). Here is the code:

&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;(function($){
if ({}.__proto__){
    // mozilla  &amp; webkit expose the prototype chain directly
    $.namespace = function(n){
        var names=n.split(&#039;.&#039;);
        var f=$.fn;
        for(var i=0;i&lt;names.length;i++) {
            var name=names[i];
            if(!f[name]) {
                f[name] = function namespace() { // insert this function in the prototype chain
                    this.__proto__ = arguments.callee;
                    return this;
                };
                f[name].__proto__ = f;
            }
            f=f[name];
        }
    };
    $.fn.$ = function(){
        this.__proto__ = $.fn;
        return this;
    };
}else{
    // every other browser; need to copy methods
    $.namespace = function(n){
        var names=n.split(&#039;.&#039;);
        var f=$.fn;
        for(var i=0;i&lt;names.length;i++) {
            var name=names[i];
            if(!f[name]) {
                f[name] = function namespace() { return this.extend(arguments.callee); };
            }
            f=f[name];
        }
    };
    $.fn.$ = function() { // slow but restores the default namespace
        var len = this.length;
        this.extend($.fn);
        this.length = len; // $.fn has length = 0, which messes everything up
        return this;
    };
}
})(jQuery);&lt;/code&gt;&lt;/pre&gt;


It allows you to do stuff like so:
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;$.namespace(&#039;danny&#039;);
$.fn.danny.foo = function() {alert(&#039;color=green&#039;); return this;};
$.namespace(&#039;danny.tools&#039;);
$.fn.danny.tools.foo = function(){alert(&#039;color=blue&#039;); return this;};
$(&#039;p&#039;).danny().foo();
$(&#039;p&#039;).danny().tools().foo();&lt;/code&gt;&lt;/pre&gt;

Creating the &quot;danny&quot; namespace first is just there to prove that any existing packages aren&#039;t overriden when they are chained.</description>
		<content:encoded><![CDATA[<p>I reworked your code a bit to allow for chained namespacing (like in java). Here is the code:</p>
<pre><code class="language-javascript">(function($){
if ({}.__proto__){
    // mozilla  &amp; webkit expose the prototype chain directly
    $.namespace = function(n){
        var names=n.split('.');
        var f=$.fn;
        for(var i=0;i&lt;names.length;i++) {
            var name=names[i];
            if(!f[name]) {
                f[name] = function namespace() { // insert this function in the prototype chain
                    this.__proto__ = arguments.callee;
                    return this;
                };
                f[name].__proto__ = f;
            }
            f=f[name];
        }
    };
    $.fn.$ = function(){
        this.__proto__ = $.fn;
        return this;
    };
}else{
    // every other browser; need to copy methods
    $.namespace = function(n){
        var names=n.split('.');
        var f=$.fn;
        for(var i=0;i&lt;names.length;i++) {
            var name=names[i];
            if(!f[name]) {
                f[name] = function namespace() { return this.extend(arguments.callee); };
            }
            f=f[name];
        }
    };
    $.fn.$ = function() { // slow but restores the default namespace
        var len = this.length;
        this.extend($.fn);
        this.length = len; // $.fn has length = 0, which messes everything up
        return this;
    };
}
})(jQuery);</code></pre>
<p>It allows you to do stuff like so:</p>
<pre><code class="language-javascript">$.namespace('danny');
$.fn.danny.foo = function() {alert('color=green'); return this;};
$.namespace('danny.tools');
$.fn.danny.tools.foo = function(){alert('color=blue'); return this;};
$('p').danny().foo();
$('p').danny().tools().foo();</code></pre>
<p>Creating the &#8220;danny&#8221; namespace first is just there to prove that any existing packages aren&#8217;t overriden when they are chained.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
