<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: A Plugin Development Pattern</title>
	<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern</link>
	<description>Getting to know the library of choice for unobtrusive JavaScript</description>
	<pubDate>Fri, 25 Jul 2008 03:37:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Website Design</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-48667</link>
		<dc:creator>Website Design</dc:creator>
		<pubDate>Mon, 02 Jun 2008 18:55:13 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-48667</guid>
		<description>I almost always enjoy what I read on this site. :)</description>
		<content:encoded><![CDATA[<p>I almost always enjoy what I read on this site. <img src='http://www.learningjquery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-44435</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Fri, 02 May 2008 13:17:51 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-44435</guid>
		<description>Hi! That was a great article, but I still have a question:
If you extend the options this way and the user doesn't set all the new defaults then some options may be missing that can easily cause problem (as they will be undefined). If each properties are set it doesn't matter but only if a new object is given as defaults, which is more convenient in most cases.
So, wouldn't be better:
&lt;code&gt;
//defaults inside the plugin:
var defaults = {
  foreground: 'red',
  background: 'yellow'
};

$.extend( defaults, $.fn.pluginName.defaults, options )
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Hi! That was a great article, but I still have a question:<br />
If you extend the options this way and the user doesn&#8217;t set all the new defaults then some options may be missing that can easily cause problem (as they will be undefined). If each properties are set it doesn&#8217;t matter but only if a new object is given as defaults, which is more convenient in most cases.<br />
So, wouldn&#8217;t be better:<br />
<code><br />
//defaults inside the plugin:<br />
var defaults = {<br />
  foreground: 'red',<br />
  background: 'yellow'<br />
};</p>
<p>$.extend( defaults, $.fn.pluginName.defaults, options )<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michael</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-40857</link>
		<dc:creator>michael</dc:creator>
		<pubDate>Wed, 16 Apr 2008 17:44:41 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-40857</guid>
		<description>I looked at different plugins code and this is definitely the best plugin pattern I found. Many thanks for that great tutorial!!</description>
		<content:encoded><![CDATA[<p>I looked at different plugins code and this is definitely the best plugin pattern I found. Many thanks for that great tutorial!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edilson de Souza</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-35523</link>
		<dc:creator>Edilson de Souza</dc:creator>
		<pubDate>Mon, 31 Mar 2008 03:31:10 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-35523</guid>
		<description>Hails! Mike, I've been writing a plugin and I wanna know about the flexibility of writing in a OO manner, like so:
&lt;code&gt;(&lt;strong&gt;function&lt;/strong&gt;($){
&#160;&#160;&#160;&#160;$.myClassName = {

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;calcSomething:  &lt;strong&gt;function&lt;/strong&gt;(arg){  
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//do something
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;},

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;main: &lt;strong&gt;function&lt;/strong&gt;(){

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;strong&gt;return&lt;/strong&gt; &lt;code&gt;this&lt;/code&gt;.each(&lt;strong&gt;function&lt;/strong&gt;(){
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//do something more
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$.myClassName.calcSomething(param){

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;$.fn.myMethod = $.myClassName.main;
})(jQuery);

I'd like to know your opinion about that OO pattern in jQuery plugins.
Thanks for your article!</description>
		<content:encoded><![CDATA[<p>Hails! Mike, I&#8217;ve been writing a plugin and I wanna know about the flexibility of writing in a OO manner, like so:<br />
<code>(<strong>function</strong>($){<br />
&nbsp;&nbsp;&nbsp;&nbsp;$.myClassName = {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;calcSomething:  <strong>function</strong>(arg){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//do something<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;main: <strong>function</strong>(){</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>return</strong> </code><code>this</code>.each(<strong>function</strong>(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//do something more<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$.myClassName.calcSomething(param){</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;$.fn.myMethod = $.myClassName.main;<br />
})(jQuery);</p>
<p>I&#8217;d like to know your opinion about that OO pattern in jQuery plugins.<br />
Thanks for your article!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexandre Magno</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-35142</link>
		<dc:creator>Alexandre Magno</dc:creator>
		<pubDate>Fri, 28 Mar 2008 14:24:29 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-35142</guid>
		<description>Im working in a big project of ajax and I would like to use a plugin
pattern thats not working in pratice...

All javascript in the project I would like to transform in a jQuery
plugin. But to achieve this I need to separate in categories in
libraries for this site Im working

So, I wanna to make this:

$("seletor").project.ajax.remote();

$("seletor").helpers.options();

But when Im creating a plugin like this:

$.fn.project.ajax.remote = function() {
//code

}

Its not working...

Using extend I reach it, but extending methods of jQuery objects  I
cant do that. I need this because I create a ajax library just for the
site and a lot of thing, so we need this pattern...

How I can accomplish this????</description>
		<content:encoded><![CDATA[<p>Im working in a big project of ajax and I would like to use a plugin<br />
pattern thats not working in pratice&#8230;</p>
<p>All javascript in the project I would like to transform in a jQuery<br />
plugin. But to achieve this I need to separate in categories in<br />
libraries for this site Im working</p>
<p>So, I wanna to make this:</p>
<p>$(&#8221;seletor&#8221;).project.ajax.remote();</p>
<p>$(&#8221;seletor&#8221;).helpers.options();</p>
<p>But when Im creating a plugin like this:</p>
<p>$.fn.project.ajax.remote = function() {<br />
//code</p>
<p>}</p>
<p>Its not working&#8230;</p>
<p>Using extend I reach it, but extending methods of jQuery objects  I<br />
cant do that. I need this because I create a ajax library just for the<br />
site and a lot of thing, so we need this pattern&#8230;</p>
<p>How I can accomplish this????</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexandre Plennevaux</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-34200</link>
		<dc:creator>Alexandre Plennevaux</dc:creator>
		<pubDate>Tue, 18 Mar 2008 11:01:47 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-34200</guid>
		<description>Hi Mike,
thanks for this most excellent and referential tutorial!

Could you update it to explain how to implement callbacks? Some concise background info about callbacks would be great as well.


Thank you so so much for all you do for the jquery community!

Alexandre</description>
		<content:encoded><![CDATA[<p>Hi Mike,<br />
thanks for this most excellent and referential tutorial!</p>
<p>Could you update it to explain how to implement callbacks? Some concise background info about callbacks would be great as well.</p>
<p>Thank you so so much for all you do for the jquery community!</p>
<p>Alexandre</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kean</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-33680</link>
		<dc:creator>Kean</dc:creator>
		<pubDate>Wed, 12 Mar 2008 23:17:56 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-33680</guid>
		<description>Thanks for the post. I just developed a plugin and I will implement the patterns.</description>
		<content:encoded><![CDATA[<p>Thanks for the post. I just developed a plugin and I will implement the patterns.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: malsup</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-32701</link>
		<dc:creator>malsup</dc:creator>
		<pubDate>Thu, 06 Mar 2008 12:05:04 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-32701</guid>
		<description>Frink,

I'm most definitely not suggesting anyone using namespacing to do this:

&lt;code&gt;$('selector').namespace.method().namespace.method().namespace.method()&lt;/code&gt;

As was mentioned, this article focuses on a &lt;em&gt;single&lt;/em&gt;-plugin script and the suggestion is to use a single namespace for a single plugin.  If your script has multiple plugins then you certainly need multiple &lt;code&gt;$.fn&lt;/code&gt; extension points (for example, $.fn.doSomething() and $.fn.undoSomething()).

I believe that using the plugin function for default settings and for exposing public functions is a better implementation than extending the jQuery object itself.  I suppose it's a matter of taste, but I prefer to have the entire plugin implementation packaged in the same namespace.</description>
		<content:encoded><![CDATA[<p>Frink,</p>
<p>I&#8217;m most definitely not suggesting anyone using namespacing to do this:</p>
<p><code>$('selector').namespace.method().namespace.method().namespace.method()</code></p>
<p>As was mentioned, this article focuses on a <em>single</em>-plugin script and the suggestion is to use a single namespace for a single plugin.  If your script has multiple plugins then you certainly need multiple <code>$.fn</code> extension points (for example, $.fn.doSomething() and $.fn.undoSomething()).</p>
<p>I believe that using the plugin function for default settings and for exposing public functions is a better implementation than extending the jQuery object itself.  I suppose it&#8217;s a matter of taste, but I prefer to have the entire plugin implementation packaged in the same namespace.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frink</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-32659</link>
		<dc:creator>Frink</dc:creator>
		<pubDate>Thu, 06 Mar 2008 01:22:15 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-32659</guid>
		<description>One more oops. Low blood sugar. Wasn't thinking. You should not use "private" as a variable name. instead you can use the namespace you choose.

&lt;code&gt;
// Private Variables and Methods
var namespace = {
};
// Public Variables and Methods
$.namespace {
}
&lt;/code&gt;

Sorry for the confusion. Argh! I hate not thinking straight.</description>
		<content:encoded><![CDATA[<p>One more oops. Low blood sugar. Wasn&#8217;t thinking. You should not use &#8220;private&#8221; as a variable name. instead you can use the namespace you choose.</p>
<p><code><br />
// Private Variables and Methods<br />
var namespace = {<br />
};<br />
// Public Variables and Methods<br />
$.namespace {<br />
}<br />
</code></p>
<p>Sorry for the confusion. Argh! I hate not thinking straight.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frink</title>
		<link>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-32656</link>
		<dc:creator>Frink</dc:creator>
		<pubDate>Thu, 06 Mar 2008 00:49:20 +0000</pubDate>
		<guid>http://www.learningjquery.com/2007/10/a-plugin-development-pattern#comment-32656</guid>
		<description>There are errors in my code above. I was typing fast and my connection froze when I tried to go back and edit it. The skeleton template should have been rendered:

&lt;code&gt;
(function($) {

&#160; // Private Variables and Functions
&#160; var privateVariable = {};
&#160; function privateFunction() {
&#160; &#160; // Do Something Privately
&#160; };

&#160; // Public Variables and Methods
&#160; $.namespace = {
&#160; &#160; options: {},
&#160; &#160; publicVariable: [],
&#160; &#160; publicMethod: function() {
&#160; &#160; &#160; // Do Something Publicly
&#160; &#160; }
&#160; };

&#160; // Prototype Methods
&#160; $.fn.extend({
&#160; &#160; namespaceMethod: function() {
&#160; &#160; &#160; return this.each(function() {
&#160; &#160; &#160; &#160; // Example Setting Persistent DOM Variables
&#160; &#160; &#160; &#160; this.contextVariable = 'foo';
&#160; &#160; &#160; });
&#160; &#160; },
&#160; &#160; unnamespaceMethod: function() {
&#160; &#160; &#160; return this.each(function() {
&#160; &#160; &#160; &#160; // Example Removing Persistent DOM Variables
&#160; &#160; &#160; &#160; delete this.contextVariable;
&#160; &#160; &#160; });
&#160; &#160; }
&#160; });

&#160; //Initialization Code
&#160; $(function() {
&#160; &#160; $.namespace.publicMethod();
&#160; });

})(jQuery);
&lt;/code&gt;

One final note. Although this isn't standard practice, you can greatly clarify your code by using a private object as opposed to using free-floating private functions and variable. The the private section would therefore look like this:

&lt;code&gt;
&#160; // Private Variables and Functions
&#160; var private = {
&#160; &#160; privateVariable: {},
&#160; &#160; function privateFunction() {
&#160; &#160; &#160; // Do Something Privately
&#160; &#160; }
&#160; };
&lt;/code&gt;

This way when you access private variables and methods it will be apparent in your code:

&lt;code&gt;
private.privateVariable = 'foo';
private.privateMethod('bar');
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>There are errors in my code above. I was typing fast and my connection froze when I tried to go back and edit it. The skeleton template should have been rendered:</p>
<p><code><br />
(function($) {</p>
<p>&nbsp; // Private Variables and Functions<br />
&nbsp; var privateVariable = {};<br />
&nbsp; function privateFunction() {<br />
&nbsp; &nbsp; // Do Something Privately<br />
&nbsp; };</p>
<p>&nbsp; // Public Variables and Methods<br />
&nbsp; $.namespace = {<br />
&nbsp; &nbsp; options: {},<br />
&nbsp; &nbsp; publicVariable: [],<br />
&nbsp; &nbsp; publicMethod: function() {<br />
&nbsp; &nbsp; &nbsp; // Do Something Publicly<br />
&nbsp; &nbsp; }<br />
&nbsp; };</p>
<p>&nbsp; // Prototype Methods<br />
&nbsp; $.fn.extend({<br />
&nbsp; &nbsp; namespaceMethod: function() {<br />
&nbsp; &nbsp; &nbsp; return this.each(function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; // Example Setting Persistent DOM Variables<br />
&nbsp; &nbsp; &nbsp; &nbsp; this.contextVariable = 'foo';<br />
&nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; },<br />
&nbsp; &nbsp; unnamespaceMethod: function() {<br />
&nbsp; &nbsp; &nbsp; return this.each(function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; // Example Removing Persistent DOM Variables<br />
&nbsp; &nbsp; &nbsp; &nbsp; delete this.contextVariable;<br />
&nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; }<br />
&nbsp; });</p>
<p>&nbsp; //Initialization Code<br />
&nbsp; $(function() {<br />
&nbsp; &nbsp; $.namespace.publicMethod();<br />
&nbsp; });</p>
<p>})(jQuery);<br />
</code></p>
<p>One final note. Although this isn&#8217;t standard practice, you can greatly clarify your code by using a private object as opposed to using free-floating private functions and variable. The the private section would therefore look like this:</p>
<p><code><br />
&nbsp; // Private Variables and Functions<br />
&nbsp; var private = {<br />
&nbsp; &nbsp; privateVariable: {},<br />
&nbsp; &nbsp; function privateFunction() {<br />
&nbsp; &nbsp; &nbsp; // Do Something Privately<br />
&nbsp; &nbsp; }<br />
&nbsp; };<br />
</code></p>
<p>This way when you access private variables and methods it will be apparent in your code:</p>
<p><code><br />
private.privateVariable = 'foo';<br />
private.privateMethod('bar');<br />
</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
