<?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: Event.observeMethod: More AOP for JavaScript</title>
	<atom:link href="http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 17 May 2012 07:43:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Steven Moberg</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-255473</link>
		<dc:creator>Steven Moberg</dc:creator>
		<pubDate>Thu, 13 Sep 2007 17:47:27 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-255473</guid>
		<description>I had to modify the code so that it would work with prototyped methods.  Since prototyped methods are not attached to the objects until it is initialized, the scope does not transfer to the new initialized object.

this also works with server side JScript (ASP).

&lt;code&gt;
if(!scope.listeners[method]){
     scope.listners[method] = this.getAspects();

     var $scope = scope;
     if(!$scope[method] &amp;&amp; $scope.prototype[method])
            $scope = scope.prototype;

     var _method = $scope[method];
     $scope[method] = function(){
           var arg = $(arguments);
           // using [this] scope ensures its applied to the owning object
           Event.dispatchCustomEvent(this, scope.listeners[Event.BEFORE], args);
           Event.dispatchCustomEvent(this, scope.listeners[Event.AROUND], args);

           var r = _method.apply(this, args);
           args.push(r);
           args.push(this);

           Event.dispatchCustomEvent(this, scope.listeners[Event.AROUND], args);
           Event.dispatchCustomEvent(this, scope.listeners[Event.AFTER], args);
           return r;
     }
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I had to modify the code so that it would work with prototyped methods.  Since prototyped methods are not attached to the objects until it is initialized, the scope does not transfer to the new initialized object.</p>
<p>this also works with server side JScript (ASP).</p>
<p><code><br />
if(!scope.listeners[method]){<br />
     scope.listners[method] = this.getAspects();</p>
<p>     var $scope = scope;<br />
     if(!$scope[method] &amp;&amp; $scope.prototype[method])<br />
            $scope = scope.prototype;</p>
<p>     var _method = $scope[method];<br />
     $scope[method] = function(){<br />
           var arg = $(arguments);<br />
           // using [this] scope ensures its applied to the owning object<br />
           Event.dispatchCustomEvent(this, scope.listeners[Event.BEFORE], args);<br />
           Event.dispatchCustomEvent(this, scope.listeners[Event.AROUND], args);</p>
<p>           var r = _method.apply(this, args);<br />
           args.push(r);<br />
           args.push(this);</p>
<p>           Event.dispatchCustomEvent(this, scope.listeners[Event.AROUND], args);<br />
           Event.dispatchCustomEvent(this, scope.listeners[Event.AFTER], args);<br />
           return r;<br />
     }<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vance Dubberly</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250882</link>
		<dc:creator>Vance Dubberly</dc:creator>
		<pubDate>Fri, 25 May 2007 21:15:00 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250882</guid>
		<description>Dojo has done this since forever. It&#039;s a great tool that I use regulary. Think of it in terms of GUI programming.  Create a &quot;Bean&quot; type object, you can tell your gui ( or service ) components to listen for changes in it&#039;s properties.   It lets components which are interested in an event ask to be notified when it occurs instead of forcing your dataset to be responsible for knowing about and notifying everything that is interestested in it. In otherwords it a natural extension of the existing javascript event paradigm.</description>
		<content:encoded><![CDATA[<p>Dojo has done this since forever. It&#8217;s a great tool that I use regulary. Think of it in terms of GUI programming.  Create a &#8220;Bean&#8221; type object, you can tell your gui ( or service ) components to listen for changes in it&#8217;s properties.   It lets components which are interested in an event ask to be notified when it occurs instead of forcing your dataset to be responsible for knowing about and notifying everything that is interestested in it. In otherwords it a natural extension of the existing javascript event paradigm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Cerny</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250866</link>
		<dc:creator>Robert Cerny</dc:creator>
		<pubDate>Fri, 25 May 2007 17:05:08 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250866</guid>
		<description>I am providing a library, Cerny.js, which puts emphasis on improving JavaScript development in large teams. Method call interception is one of the key ingredients of Cerny.js and it allows you to achieve dynamic type checking, tracing, profiling and programming by contract. I consider it very useful, but then again, i am the author .-) 

Read more at http://www.cerny-online.com/cerny.js !</description>
		<content:encoded><![CDATA[<p>I am providing a library, Cerny.js, which puts emphasis on improving JavaScript development in large teams. Method call interception is one of the key ingredients of Cerny.js and it allows you to achieve dynamic type checking, tracing, profiling and programming by contract. I consider it very useful, but then again, i am the author .-) </p>
<p>Read more at <a href="http://www.cerny-online.com/cerny.js" rel="nofollow">http://www.cerny-online.com/cerny.js</a> !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Johnson</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250864</link>
		<dc:creator>Ryan Johnson</dc:creator>
		<pubDate>Fri, 25 May 2007 16:30:08 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250864</guid>
		<description>Dion, you should get your comments system to automatically wrap a code tag with pre if it&#039;s not an allowed tag =)</description>
		<content:encoded><![CDATA[<p>Dion, you should get your comments system to automatically wrap a code tag with pre if it&#8217;s not an allowed tag =)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Johnson</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250863</link>
		<dc:creator>Ryan Johnson</dc:creator>
		<pubDate>Fri, 25 May 2007 16:29:17 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250863</guid>
		<description>I&#039;ve been struggling with very similar problems, but came up with two totally different solutions. For the idea of objects or methods having events I am creating a library I call Object.Event (click on my name below to go to the post), but the methods need to specify that an event is happening, i.e. this.notify(&#039;event_name&#039;);

For simple method interception or modification I use the following:

&lt;code&gt;
Function.prototype.intercept = function(interceptor){
	var original_function = this;
	return function(){
		return interceptor.apply(this,[original_function.bind(this)].concat($A(arguments)));
	};
};

test = function(str){
	alert(str);
}.intercept(function(original_function,str){
	return original_function(str.toUpperCase());
});

test(&#039;testing&#039;);
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been struggling with very similar problems, but came up with two totally different solutions. For the idea of objects or methods having events I am creating a library I call Object.Event (click on my name below to go to the post), but the methods need to specify that an event is happening, i.e. this.notify(&#8216;event_name&#8217;);</p>
<p>For simple method interception or modification I use the following:</p>
<p><code><br />
Function.prototype.intercept = function(interceptor){<br />
	var original_function = this;<br />
	return function(){<br />
		return interceptor.apply(this,[original_function.bind(this)].concat($A(arguments)));<br />
	};<br />
};</p>
<p>test = function(str){<br />
	alert(str);<br />
}.intercept(function(original_function,str){<br />
	return original_function(str.toUpperCase());<br />
});</p>
<p>test('testing');<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Kant</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250862</link>
		<dc:creator>Andy Kant</dc:creator>
		<pubDate>Fri, 25 May 2007 15:56:58 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250862</guid>
		<description>I wrote a similar script that is used to add prioritized preprocessors and postprocessors to methods while still retaining original context. Such functionality can be pretty useful, but most of the time it probably isn&#039;t worth the extra bandwidth unless its being used in a large web app.


For instance, I wrote an active record-based JavaScript database library. The base library only includes the necessary logic with no data/param validation (good for production), but I have a separate validation module that attaches to the pre-existing methods as preprocessors, ceasing operation and throwing an error as necessary.</description>
		<content:encoded><![CDATA[<p>I wrote a similar script that is used to add prioritized preprocessors and postprocessors to methods while still retaining original context. Such functionality can be pretty useful, but most of the time it probably isn&#8217;t worth the extra bandwidth unless its being used in a large web app.</p>
<p>For instance, I wrote an active record-based JavaScript database library. The base library only includes the necessary logic with no data/param validation (good for production), but I have a separate validation module that attaches to the pre-existing methods as preprocessors, ceasing operation and throwing an error as necessary.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Sanderson</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250859</link>
		<dc:creator>Adam Sanderson</dc:creator>
		<pubDate>Fri, 25 May 2007 15:43:49 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250859</guid>
		<description>Some aspect oriented programming flavor there.  At the very least it can&#039;t hurt.  I figure it could be useful for inserting activities before serializing a form or some such thing.</description>
		<content:encoded><![CDATA[<p>Some aspect oriented programming flavor there.  At the very least it can&#8217;t hurt.  I figure it could be useful for inserting activities before serializing a form or some such thing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Uriel Katz</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250857</link>
		<dc:creator>Uriel Katz</dc:creator>
		<pubDate>Fri, 25 May 2007 15:10:19 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250857</guid>
		<description>this is the same as decorators in python only less powerful</description>
		<content:encoded><![CDATA[<p>this is the same as decorators in python only less powerful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250855</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Fri, 25 May 2007 14:25:36 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250855</guid>
		<description>210 Ajax Frameworks and counting.

Should change that title to 211 Ajax Frameworks and Counting...</description>
		<content:encoded><![CDATA[<p>210 Ajax Frameworks and counting.</p>
<p>Should change that title to 211 Ajax Frameworks and Counting&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Hartmann</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250850</link>
		<dc:creator>Jon Hartmann</dc:creator>
		<pubDate>Fri, 25 May 2007 13:44:42 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250850</guid>
		<description>@Dion,
I&#039;d find this kind of thing very useful. In parts of the application I&#039;m working on I have some Event.observe&#039;s that conditionally choose when to call another function is executed. If I wanted to base another action of that function being called, I&#039;d have to duplicate the checks for the element&#039;s existence and the conditional checks to get it to fire at the same time. It also adds a layer of abstraction that changes &quot;I do funcB when this and this happen so it coincides with this funcA&quot; to &quot;I do funcB when I do funcA&quot;.</description>
		<content:encoded><![CDATA[<p>@Dion,<br />
I&#8217;d find this kind of thing very useful. In parts of the application I&#8217;m working on I have some Event.observe&#8217;s that conditionally choose when to call another function is executed. If I wanted to base another action of that function being called, I&#8217;d have to duplicate the checks for the element&#8217;s existence and the conditional checks to get it to fire at the same time. It also adds a layer of abstraction that changes &#8220;I do funcB when this and this happen so it coincides with this funcA&#8221; to &#8220;I do funcB when I do funcA&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg</title>
		<link>http://ajaxian.com/archives/eventobservemethod-more-aop-for-javascript/comment-page-1#comment-250846</link>
		<dc:creator>Greg</dc:creator>
		<pubDate>Fri, 25 May 2007 13:25:59 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2433#comment-250846</guid>
		<description>Broken link?</description>
		<content:encoded><![CDATA[<p>Broken link?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

