<?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: How to do a non-destructive overwrite of a function in javascript</title>
	<atom:link href="http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/</link>
	<description>Advanced katas for javascripters</description>
	<lastBuildDate>Fri, 30 Jul 2010 18:10:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Stephan Wehner</title>
		<link>http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/comment-page-1/#comment-478</link>
		<dc:creator>Stephan Wehner</dc:creator>
		<pubDate>Mon, 02 Jun 2008 08:05:44 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=36#comment-478</guid>
		<description>Couldn&#039;t get this to work with &quot;console.debug&quot; (which comes with Firebug, for Firefox) -- I got &quot;too many recursions&quot; with

var origcd = console.debug
console.debug = function(s) { 
  origcd(&#039;console-debug: &#039; + s)
}
:
:
:
console.debug(&#039;test&#039;)

console.debug writes to a console, that can be viewed with Firebug.

Stephan</description>
		<content:encoded><![CDATA[<p>Couldn&#8217;t get this to work with &#8220;console.debug&#8221; (which comes with Firebug, for Firefox) &#8212; I got &#8220;too many recursions&#8221; with</p>
<p>var origcd = console.debug<br />
console.debug = function(s) {<br />
  origcd(&#8216;console-debug: &#8216; + s)<br />
}<br />
:<br />
:<br />
:<br />
console.debug(&#8216;test&#8217;)</p>
<p>console.debug writes to a console, that can be viewed with Firebug.</p>
<p>Stephan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BK</title>
		<link>http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/comment-page-1/#comment-198</link>
		<dc:creator>BK</dc:creator>
		<pubDate>Tue, 22 May 2007 14:11:39 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=36#comment-198</guid>
		<description>What do you mean by DOM Level 2?
Are you talking about the register event stuff?</description>
		<content:encoded><![CDATA[<p>What do you mean by DOM Level 2?<br />
Are you talking about the register event stuff?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Craig</title>
		<link>http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/comment-page-1/#comment-197</link>
		<dc:creator>James Craig</dc:creator>
		<pubDate>Sat, 19 May 2007 20:31:24 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=36#comment-197</guid>
		<description>Even without a library, try DOM Level 2 assignment and you won&#039;t overwrite any of these DOM 1 assignments or other DOM 2 events.</description>
		<content:encoded><![CDATA[<p>Even without a library, try DOM Level 2 assignment and you won&#8217;t overwrite any of these DOM 1 assignments or other DOM 2 events.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Becker</title>
		<link>http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/comment-page-1/#comment-196</link>
		<dc:creator>Scott Becker</dc:creator>
		<pubDate>Mon, 07 May 2007 20:07:30 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=36#comment-196</guid>
		<description>Since you&#039;re not really overwriting the function, but adding before and after callbacks, ActsAsAspect is an elegant way of doing this - http://beppu.lbox.org/articles/2006/09/06/actsasaspect

Basically, you can take a function or object or class with some existing methods:

  MyObj.go = function() { alert(&#039;go&#039;); }

and call actsAsAspect() on it like so:

  actsAsAspect(MyObj);

then it gets some some extra methods - before, after, &amp; around, which let you add listeners to that function like this:

MyObj.before(&#039;go&#039;, function() { alert(&#039;do this before go() gets called!&#039;) })

It&#039;s short and sweet, I love that little script.</description>
		<content:encoded><![CDATA[<p>Since you&#8217;re not really overwriting the function, but adding before and after callbacks, ActsAsAspect is an elegant way of doing this &#8211; <a href="http://beppu.lbox.org/articles/2006/09/06/actsasaspect" rel="nofollow">http://beppu.lbox.org/articles/2006/09/06/actsasaspect</a></p>
<p>Basically, you can take a function or object or class with some existing methods:</p>
<p>  MyObj.go = function() { alert(&#8216;go&#8217;); }</p>
<p>and call actsAsAspect() on it like so:</p>
<p>  actsAsAspect(MyObj);</p>
<p>then it gets some some extra methods &#8211; before, after, &amp; around, which let you add listeners to that function like this:</p>
<p>MyObj.before(&#8216;go&#8217;, function() { alert(&#8216;do this before go() gets called!&#8217;) })</p>
<p>It&#8217;s short and sweet, I love that little script.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: si</title>
		<link>http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/comment-page-1/#comment-195</link>
		<dc:creator>si</dc:creator>
		<pubDate>Fri, 04 May 2007 21:34:04 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=36#comment-195</guid>
		<description>While I don&#039;t like that method of event adding (I think a nice cross-browser addEvent function is far safer / nicer), it&#039;s quite a pretty way of doing it - one good consequence is that you can specify whether yours happens before or after all of the existing methods.

Another similar &quot;trick&quot; which I like is overriding the alert() function to get rid of potentially missed debug code, like so:

_alert = alert;
alert = null;</description>
		<content:encoded><![CDATA[<p>While I don&#8217;t like that method of event adding (I think a nice cross-browser addEvent function is far safer / nicer), it&#8217;s quite a pretty way of doing it &#8211; one good consequence is that you can specify whether yours happens before or after all of the existing methods.</p>
<p>Another similar &#8220;trick&#8221; which I like is overriding the alert() function to get rid of potentially missed debug code, like so:</p>
<p>_alert = alert;<br />
alert = null;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/comment-page-1/#comment-194</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Fri, 04 May 2007 14:14:11 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=36#comment-194</guid>
		<description>@Boyan
I guess that a lot of librairies can take care of this... but sometimes you don&#039;t have any librairie for a small web site or a bookmarklet...

Thanks for the correction...</description>
		<content:encoded><![CDATA[<p>@Boyan<br />
I guess that a lot of librairies can take care of this&#8230; but sometimes you don&#8217;t have any librairie for a small web site or a bookmarklet&#8230;</p>
<p>Thanks for the correction&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Boyan</title>
		<link>http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/comment-page-1/#comment-193</link>
		<dc:creator>Boyan</dc:creator>
		<pubDate>Fri, 04 May 2007 13:38:29 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=36#comment-193</guid>
		<description>Nice. Don&#039;t most js libraries take care of this automatically already? Oh, and by the way (nitpick coming), the past tense of &quot;stick&quot; is &quot;stuck&quot; and not &quot;stucked&quot;</description>
		<content:encoded><![CDATA[<p>Nice. Don&#8217;t most js libraries take care of this automatically already? Oh, and by the way (nitpick coming), the past tense of &#8220;stick&#8221; is &#8220;stuck&#8221; and not &#8220;stucked&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BK</title>
		<link>http://www.javascriptkata.com/2007/05/03/how-to-do-a-non-destructive-overwrite-of-a-function-in-javascript/comment-page-1/#comment-192</link>
		<dc:creator>BK</dc:creator>
		<pubDate>Thu, 03 May 2007 15:02:09 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=36#comment-192</guid>
		<description>Here come the recuer again! :P Here Comes: THE CLOSURE!



function FnBuilder(){
	var Old=document.getElementById(&quot;myb&quot;).onclick
	function New(){Old();alert(5678);}
	return New
}
document.getElementById(&#039;myb&#039;).onclick=FnBuilder();
FnBuilder=null;</description>
		<content:encoded><![CDATA[<p>Here come the recuer again! <img src='http://www.javascriptkata.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  Here Comes: THE CLOSURE!</p>
<p>function FnBuilder(){<br />
	var Old=document.getElementById(&#8220;myb&#8221;).onclick<br />
	function New(){Old();alert(5678);}<br />
	return New<br />
}<br />
document.getElementById(&#8216;myb&#8217;).onclick=FnBuilder();<br />
FnBuilder=null;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
