<?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: JavaScript decorator pattern</title>
	<atom:link href="http://lostechies.com/jimmybogard/2009/01/20/javascript-decorator-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2009/01/20/javascript-decorator-pattern/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Thu, 23 May 2013 23:40:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/01/20/javascript-decorator-pattern/#comment-1181</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Wed, 21 Jan 2009 12:16:56 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/01/20/javascript-decorator-pattern.aspx#comment-1181</guid>
		<description>@Brian C

Ha, I knew I was forgetting something!  I&#039;ll check out that change, thanks!</description>
		<content:encoded><![CDATA[<p>@Brian C</p>
<p>Ha, I knew I was forgetting something!  I&#8217;ll check out that change, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian C</title>
		<link>http://lostechies.com/jimmybogard/2009/01/20/javascript-decorator-pattern/#comment-1180</link>
		<dc:creator>Brian C</dc:creator>
		<pubDate>Wed, 21 Jan 2009 07:12:51 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/01/20/javascript-decorator-pattern.aspx#comment-1180</guid>
		<description>two things: 

first...
I should have actually invoked the offending function...in your minds eye, append this to the above code:
bang.sayHello();
word....

second...
You can modify your before and after functions to take a &quot;scope&quot; or &quot;execution context&quot; as their argument to optionally apply an execution context to the method...

Function.method(&#039;before&#039;, function(beforeFunc,scope) {
    var that = this;
    return function() {
        beforeFunc.apply(scope, arguments);
        return that.apply(scope, arguments);
    };
});

My first example&#039;s invocation of &quot;before&quot; could be modified to as follows:

}.before(function(){/*do nothing*/},this) and I believe the sayHello method would not cause an error....unfortunately it&#039;s too late and I&#039;m too lazy to test this out. So...I might be wrong.

Either way, thanks to JS&#039;s optional method parameters this modification is a completely backwards compatible change. :D</description>
		<content:encoded><![CDATA[<p>two things: </p>
<p>first&#8230;<br />
I should have actually invoked the offending function&#8230;in your minds eye, append this to the above code:<br />
bang.sayHello();<br />
word&#8230;.</p>
<p>second&#8230;<br />
You can modify your before and after functions to take a &#8220;scope&#8221; or &#8220;execution context&#8221; as their argument to optionally apply an execution context to the method&#8230;</p>
<p>Function.method(&#8216;before&#8217;, function(beforeFunc,scope) {<br />
    var that = this;<br />
    return function() {<br />
        beforeFunc.apply(scope, arguments);<br />
        return that.apply(scope, arguments);<br />
    };<br />
});</p>
<p>My first example&#8217;s invocation of &#8220;before&#8221; could be modified to as follows:</p>
<p>}.before(function(){/*do nothing*/},this) and I believe the sayHello method would not cause an error&#8230;.unfortunately it&#8217;s too late and I&#8217;m too lazy to test this out. So&#8230;I might be wrong.</p>
<p>Either way, thanks to JS&#8217;s optional method parameters this modification is a completely backwards compatible change. <img src='http://lostechies.com/jimmybogard/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian C</title>
		<link>http://lostechies.com/jimmybogard/2009/01/20/javascript-decorator-pattern/#comment-1179</link>
		<dc:creator>Brian C</dc:creator>
		<pubDate>Wed, 21 Jan 2009 05:56:37 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/01/20/javascript-decorator-pattern.aspx#comment-1179</guid>
		<description>Might want to check out what happens when you do the following:

var bang = function(){
   return{
      name:&quot;Jimmy&quot;,
      sayHello:function(){
           alert(&quot;Hello from &quot; + this.name);
      }.before(function(){/*do nothing*/})
   }
}()

using &quot;apply&quot; with null as the first argument removes the &quot;this&quot; context of the original function, so any reference to &quot;this&quot; inside the function returned from &quot;before&quot; or &quot;after&quot; methods might result in some unhappy times.</description>
		<content:encoded><![CDATA[<p>Might want to check out what happens when you do the following:</p>
<p>var bang = function(){<br />
   return{<br />
      name:&#8221;Jimmy&#8221;,<br />
      sayHello:function(){<br />
           alert(&#8220;Hello from &#8221; + this.name);<br />
      }.before(function(){/*do nothing*/})<br />
   }<br />
}()</p>
<p>using &#8220;apply&#8221; with null as the first argument removes the &#8220;this&#8221; context of the original function, so any reference to &#8220;this&#8221; inside the function returned from &#8220;before&#8221; or &#8220;after&#8221; methods might result in some unhappy times.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergio Pereira</title>
		<link>http://lostechies.com/jimmybogard/2009/01/20/javascript-decorator-pattern/#comment-1178</link>
		<dc:creator>Sergio Pereira</dc:creator>
		<pubDate>Wed, 21 Jan 2009 02:39:47 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/01/20/javascript-decorator-pattern.aspx#comment-1178</guid>
		<description>Irony is unforgiving. BLOCKED SCRIPT describes very well how much we still have to go.</description>
		<content:encoded><![CDATA[<p>Irony is unforgiving. BLOCKED SCRIPT describes very well how much we still have to go.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
