<?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: Building your own Javascript library (part 1)</title>
	<atom:link href="http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/</link>
	<description>An analog guy in a digital world</description>
	<lastBuildDate>Wed, 18 Aug 2010 19:35:56 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Building your own Javascript library (part 2)</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-3407</link>
		<dc:creator>Building your own Javascript library (part 2)</dc:creator>
		<pubDate>Wed, 18 Aug 2010 19:35:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-3407</guid>
		<description>[...] my previous blog post, there were some extra&#8217;s there: settings and an init method. I won&#8217;t be needing those [...]</description>
		<content:encoded><![CDATA[<p>[...] my previous blog post, there were some extra&#8217;s there: settings and an init method. I won&#8217;t be needing those [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Building your own Javascript library (part 3)</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-3406</link>
		<dc:creator>Building your own Javascript library (part 3)</dc:creator>
		<pubDate>Wed, 18 Aug 2010 19:14:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-3406</guid>
		<description>[...] going to start with some amends to the functionality I have already created in the first part of the series. Don&#8217;t know if you remember, but there I created functionality that is copied [...]</description>
		<content:encoded><![CDATA[<p>[...] going to start with some amends to the functionality I have already created in the first part of the series. Don&#8217;t know if you remember, but there I created functionality that is copied [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-3019</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Tue, 13 Jul 2010 09:33:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-3019</guid>
		<description>Hi Nizzy,

You could try to add the onError event handler to the Tag object. More info can be found here: http://api.jquery.com/error/
If that isn&#039;t enough, you can also look to place try/catch statements where appropriate (haven&#039;t really looked into that yet, so I don&#039;t have a recommendation where to put those)

Tom</description>
		<content:encoded><![CDATA[<p>Hi Nizzy,</p>
<p>You could try to add the onError event handler to the Tag object. More info can be found here: <a href="http://api.jquery.com/error/" rel="nofollow">http://api.jquery.com/error/</a><br />
If that isn&#8217;t enough, you can also look to place try/catch statements where appropriate (haven&#8217;t really looked into that yet, so I don&#8217;t have a recommendation where to put those)</p>
<p>Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nizzy</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-2970</link>
		<dc:creator>Nizzy</dc:creator>
		<pubDate>Thu, 08 Jul 2010 01:41:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-2970</guid>
		<description>Tom, thanks for sharing your work.

I was wondering how you could implement a debug pattern that allows me to catch any errors from plugins within Tag obj.

Best
Nizzy</description>
		<content:encoded><![CDATA[<p>Tom, thanks for sharing your work.</p>
<p>I was wondering how you could implement a debug pattern that allows me to catch any errors from plugins within Tag obj.</p>
<p>Best<br />
Nizzy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom&#39;s Blog &#187; Building your own Javascript library (part 3)</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-1531</link>
		<dc:creator>Tom&#39;s Blog &#187; Building your own Javascript library (part 3)</dc:creator>
		<pubDate>Wed, 02 Dec 2009 17:00:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-1531</guid>
		<description>[...] going to start with some amends to the functionality I have already created in the first part of the series. Don&#8217;t know if you remember, but there I created functionality that is copied [...]</description>
		<content:encoded><![CDATA[<p>[...] going to start with some amends to the functionality I have already created in the first part of the series. Don&#8217;t know if you remember, but there I created functionality that is copied [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-1528</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Wed, 02 Dec 2009 14:28:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-1528</guid>
		<description>Hi Mickael, thanks for your feedback.
I have thought about it for some time, and my conclusion was that it is not the job of the pubsub provider to make sure that the context is correct.

For this reason, I have created a new function in the core plugin: &quot;hitch&quot;. The name and a good deal of the logic came from the dojo.hitch function.

I won&#039;t go into details right here. I&#039;m going to start writing my new article in a couple of minutes. There I&#039;ll explain everything in detail. I&#039;m happy with the solution I came up with, and I hope you&#039;ll like it too.</description>
		<content:encoded><![CDATA[<p>Hi Mickael, thanks for your feedback.<br />
I have thought about it for some time, and my conclusion was that it is not the job of the pubsub provider to make sure that the context is correct.</p>
<p>For this reason, I have created a new function in the core plugin: &#8220;hitch&#8221;. The name and a good deal of the logic came from the dojo.hitch function.</p>
<p>I won&#8217;t go into details right here. I&#8217;m going to start writing my new article in a couple of minutes. There I&#8217;ll explain everything in detail. I&#8217;m happy with the solution I came up with, and I hope you&#8217;ll like it too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mickael</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-1524</link>
		<dc:creator>Mickael</dc:creator>
		<pubDate>Wed, 02 Dec 2009 10:08:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-1524</guid>
		<description>&lt;a href=&quot;#comment-1521&quot; rel=&quot;nofollow&quot;&gt;@Tom&lt;/a&gt; 
Ok I understand ! The first argument to your subscribe method is the plugin that&#039;ll send the notification, not the plugin that actually subscribes to be notified later...

In my logic, the &quot;this&quot; context should be :

- the plugin that subscribed to the notification if set
- nothing if it&#039;s a global namespace subscription

This will surely ask some work, some proxy function in the &quot;core&quot; class to be able to tell:

this.subscribeToEvent(plugin,event, function);

and inside :

this.subscribeToEvent = function (plugin,event,function) {
   me.getPubsubProvider().subscribe(plugin,event,function,this);
};

and of course :

subscribe:function(plugin, evt, fn,context){
            var path = this._constructPath([plugin, evt]);
            if (typeof this.subscriptions[path] === &#039;undefined&#039;) {
                this.subscriptions[path] = [];
            }

            var subscription_id = this.subscriptions[path].length;
            this.subscriptions[path].push({
                path:path,
                index: subscription_id,
                context: context,
                callback: fn
            });

            return (subscription_id);
        }

and finally:

notify:function(plugin, evt) {
            var path = this._constructPath([plugin, evt]);
            if (typeof this.subscriptions[path] !== &#039;undefined&#039;) {
                for(var i=0,l=this.subscriptions[path].length;i&lt;l;i++){
                    // make sure we only execute functions, not strings, integers, null&#039;s, ...
                    if (typeof this.subscriptions[path][i].callback === &#039;function&#039;) {
                        if ( this.subscriptions[path][i].context ) {
                              this.subscriptions[path][i].callback.call(context);
                        } else {
                              this.subscriptions[path][i].callback();
                        }
                    }
                }
            }
        },


However I&#039;m not good enough in javascript to be sure this is the cool &amp; good way to do it.</description>
		<content:encoded><![CDATA[<p><a href="#comment-1521" rel="nofollow">@Tom</a><br />
Ok I understand ! The first argument to your subscribe method is the plugin that&#8217;ll send the notification, not the plugin that actually subscribes to be notified later&#8230;</p>
<p>In my logic, the &#8220;this&#8221; context should be :</p>
<p>- the plugin that subscribed to the notification if set<br />
- nothing if it&#8217;s a global namespace subscription</p>
<p>This will surely ask some work, some proxy function in the &#8220;core&#8221; class to be able to tell:</p>
<p>this.subscribeToEvent(plugin,event, function);</p>
<p>and inside :</p>
<p>this.subscribeToEvent = function (plugin,event,function) {<br />
   me.getPubsubProvider().subscribe(plugin,event,function,this);<br />
};</p>
<p>and of course :</p>
<p>subscribe:function(plugin, evt, fn,context){<br />
            var path = this._constructPath([plugin, evt]);<br />
            if (typeof this.subscriptions[path] === &#8216;undefined&#8217;) {<br />
                this.subscriptions[path] = [];<br />
            }</p>
<p>            var subscription_id = this.subscriptions[path].length;<br />
            this.subscriptions[path].push({<br />
                path:path,<br />
                index: subscription_id,<br />
                context: context,<br />
                callback: fn<br />
            });</p>
<p>            return (subscription_id);<br />
        }</p>
<p>and finally:</p>
<p>notify:function(plugin, evt) {<br />
            var path = this._constructPath([plugin, evt]);<br />
            if (typeof this.subscriptions[path] !== &#8216;undefined&#8217;) {<br />
                for(var i=0,l=this.subscriptions[path].length;i&lt;l;i++){<br />
                    // make sure we only execute functions, not strings, integers, null&#039;s, &#8230;<br />
                    if (typeof this.subscriptions[path][i].callback === &#039;function&#039;) {<br />
                        if ( this.subscriptions[path][i].context ) {<br />
                              this.subscriptions[path][i].callback.call(context);<br />
                        } else {<br />
                              this.subscriptions[path][i].callback();<br />
                        }<br />
                    }<br />
                }<br />
            }<br />
        },</p>
<p>However I&#039;m not good enough in javascript to be sure this is the cool &amp; good way to do it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uberVU - social comments</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-1522</link>
		<dc:creator>uberVU - social comments</dc:creator>
		<pubDate>Wed, 02 Dec 2009 09:32:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-1522</guid>
		<description>&lt;strong&gt;Social comments and analytics for this post...&lt;/strong&gt;

This post was mentioned on Twitter by jQuery_Tips: Building your own Javascript library (part 1) #jQuery #Javascript http://j.mp/4WBQ0I...</description>
		<content:encoded><![CDATA[<p><strong>Social comments and analytics for this post&#8230;</strong></p>
<p>This post was mentioned on Twitter by jQuery_Tips: Building your own Javascript library (part 1) #jQuery #Javascript <a href="http://j.mp/4WBQ0I.." rel="nofollow">http://j.mp/4WBQ0I..</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-1521</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Wed, 02 Dec 2009 09:15:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-1521</guid>
		<description>Hi Mickael,

If you look at the commit history of the pubsub plugin, you&#039;ll see that at one point, I actually did what you suggested:

this.subscriptions[path][i].call(this);

But there were two things with that:
1. This refered to the pubsub scope, which isn&#039;t good
2. This way, callbacks that reside in the global namespace, would have their scope changed to the one of the plugin that notified the event.

At the moment, I&#039;m still thinking about how to solve this. Besides that, I also want to be able to return parameters to the subscribed functions. I&#039;ll find a solution later today (I hope), and you&#039;ll read about it in the next article.

Thanks for your feedback!</description>
		<content:encoded><![CDATA[<p>Hi Mickael,</p>
<p>If you look at the commit history of the pubsub plugin, you&#8217;ll see that at one point, I actually did what you suggested:</p>
<p>this.subscriptions[path][i].call(this);</p>
<p>But there were two things with that:<br />
1. This refered to the pubsub scope, which isn&#8217;t good<br />
2. This way, callbacks that reside in the global namespace, would have their scope changed to the one of the plugin that notified the event.</p>
<p>At the moment, I&#8217;m still thinking about how to solve this. Besides that, I also want to be able to return parameters to the subscribed functions. I&#8217;ll find a solution later today (I hope), and you&#8217;ll read about it in the next article.</p>
<p>Thanks for your feedback!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mickael</title>
		<link>http://www.encapsulated.org/blog/2009/11/30/building-your-own-javascript-library-part-1/comment-page-1/#comment-1520</link>
		<dc:creator>Mickael</dc:creator>
		<pubDate>Wed, 02 Dec 2009 09:08:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.encapsulated.org/blog/?p=89#comment-1520</guid>
		<description>Hello,

really really really good article, thanks &amp; keep up the good work !

I looked at your pubsub plugin ( http://www.codaset.com/theanalogguy/the-analog-guy-javascript-library/source/master/blob/tag/tag.pubsub.js ) and want to ask you :

to notify you run the subscribed anonymous function like so :

this.subscriptions[path][i]();


However this does not tell the function to run in the plugin namespace: in other words &quot;this&quot; does not point to the plugin object that is notified. Just upgrading to :

this.subscriptions[path][i].call( //some code to find the plugin inside window.Tag// );

will automagically set &quot;this&quot; to the notified plugin. Note that Jquery does it : 

$(&#039;#foo&#039;).click(function() {
  //this is the jquery object $(&#039;#foo&#039;)
});

Mickael</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>really really really good article, thanks &amp; keep up the good work !</p>
<p>I looked at your pubsub plugin ( <a href="http://www.codaset.com/theanalogguy/the-analog-guy-javascript-library/source/master/blob/tag/tag.pubsub.js" rel="nofollow">http://www.codaset.com/theanalogguy/the-analog-guy-javascript-library/source/master/blob/tag/tag.pubsub.js</a> ) and want to ask you :</p>
<p>to notify you run the subscribed anonymous function like so :</p>
<p>this.subscriptions[path][i]();</p>
<p>However this does not tell the function to run in the plugin namespace: in other words &#8220;this&#8221; does not point to the plugin object that is notified. Just upgrading to :</p>
<p>this.subscriptions[path][i].call( //some code to find the plugin inside window.Tag// );</p>
<p>will automagically set &#8220;this&#8221; to the notified plugin. Note that Jquery does it : </p>
<p>$(&#8216;#foo&#8217;).click(function() {<br />
  //this is the jquery object $(&#8216;#foo&#8217;)<br />
});</p>
<p>Mickael</p>
]]></content:encoded>
	</item>
</channel>
</rss>
