<?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: Today&#8217;s JavaScript WTF</title>
	<atom:link href="http://www.clientcide.com/jsexamples/todays-javascript-wtf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/</link>
	<description>Making stuff work on the other side of the request.</description>
	<lastBuildDate>Tue, 05 Jan 2010 18:16:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Geary</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31605</link>
		<dc:creator>Geary</dc:creator>
		<pubDate>Sun, 23 Nov 2008 01:57:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31605</guid>
		<description>It figures that I missed something in the original code. It accepts a string as the first argument, which can be either a function definition or the name of a function. Here&#039;s a version that allows that:

&lt;code&gt;function DeferCall( fn ) {
	if( typeof fn == &#039;string&#039; )
        eval( &#039;fn = &#039; + fn );
	if( typeof fn != &#039;function&#039; )
		return null;
	var args = [];
	for( var i = 1, n = arguments.length;  i &lt; n;  ++i )
		args[i-1] = &#039;arguments[&#039; + i + &#039;]&#039;;
	return eval( &#039;fn(&#039; + args.join(&#039;,&#039;) + &#039;)&#039; );
}&lt;/code&gt;

and some tests:

&lt;code&gt;function myfn( a, b ) { return a + b; }
alert( DeferCall() );
alert( DeferCall( function() { return &#039;none&#039;; } ) );
alert( DeferCall( &#039;function( a ) { return a; }&#039;, &#039;A&#039; ) );
alert( DeferCall( myfn, &#039;A&#039;, &#039;B&#039; ) );
alert( DeferCall( function( a, b, c ) { return a + b + c; }, &#039;A&#039;, &#039;B&#039;, &#039;C&#039; ) );
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>It figures that I missed something in the original code. It accepts a string as the first argument, which can be either a function definition or the name of a function. Here&#8217;s a version that allows that:</p>
<p><code>function DeferCall( fn ) {<br />
	if( typeof fn == 'string' )<br />
        eval( 'fn = ' + fn );<br />
	if( typeof fn != 'function' )<br />
		return null;<br />
	var args = [];<br />
	for( var i = 1, n = arguments.length;  i &lt; n;  ++i )<br />
		args[i-1] = 'arguments[' + i + ']';<br />
	return eval( 'fn(' + args.join(',') + ')' );<br />
}</code></p>
<p>and some tests:</p>
<p><code>function myfn( a, b ) { return a + b; }<br />
alert( DeferCall() );<br />
alert( DeferCall( function() { return 'none'; } ) );<br />
alert( DeferCall( 'function( a ) { return a; }', 'A' ) );<br />
alert( DeferCall( myfn, 'A', 'B' ) );<br />
alert( DeferCall( function( a, b, c ) { return a + b + c; }, 'A', 'B', 'C' ) );<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geary</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31604</link>
		<dc:creator>Geary</dc:creator>
		<pubDate>Sat, 22 Nov 2008 23:32:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31604</guid>
		<description>emailtoid is on the right track. You can simplify that code just a bit. Here&#039;s a complete replacement for the original function:

&lt;code&gt;
function DeferCall( fn ) {
	if( typeof fn != &#039;function&#039; )
		return null;
	var args = [];
	for( var i = 1, n = arguments.length;  i &lt; n;  ++i )
		args[i-1] = &#039;arguments[&#039; + i + &#039;]&#039;;
	return eval( &#039;fn(&#039; + args.join(&#039;,&#039;) + &#039;)&#039; );
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>emailtoid is on the right track. You can simplify that code just a bit. Here&#8217;s a complete replacement for the original function:</p>
<p><code><br />
function DeferCall( fn ) {<br />
	if( typeof fn != 'function' )<br />
		return null;<br />
	var args = [];<br />
	for( var i = 1, n = arguments.length;  i &lt; n;  ++i )<br />
		args[i-1] = 'arguments[' + i + ']';<br />
	return eval( 'fn(' + args.join(',') + ')' );<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Reddit crowd weighs in on the JavaScript WTF &#187; Clientcide (Formerly CNET&#8217;s Clientside)</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31603</link>
		<dc:creator>The Reddit crowd weighs in on the JavaScript WTF &#187; Clientcide (Formerly CNET&#8217;s Clientside)</dc:creator>
		<pubDate>Sat, 22 Nov 2008 08:31:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31603</guid>
		<description>[...] point out that the code in question (on a Function.apply method for IE5) that I understand why Microsoft would write such a hack, as IE5 doesn&#8217;t have a suitable [...]</description>
		<content:encoded><![CDATA[<p>[...] point out that the code in question (on a Function.apply method for IE5) that I understand why Microsoft would write such a hack, as IE5 doesn&#8217;t have a suitable [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron N.</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31598</link>
		<dc:creator>Aaron N.</dc:creator>
		<pubDate>Fri, 21 Nov 2008 19:46:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31598</guid>
		<description>Jesper, using .apply would be the best way to accomplish it, but Bertrand&#039;s point is that you can&#039;t use .apply for older versions of IE, and cutting support for it isn&#039;t something MSFT is willing to do. My point was to use .apply for everything else and only use the hack for ie5.</description>
		<content:encoded><![CDATA[<p>Jesper, using .apply would be the best way to accomplish it, but Bertrand&#8217;s point is that you can&#8217;t use .apply for older versions of IE, and cutting support for it isn&#8217;t something MSFT is willing to do. My point was to use .apply for everything else and only use the hack for ie5.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesper</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31597</link>
		<dc:creator>Jesper</dc:creator>
		<pubDate>Fri, 21 Nov 2008 19:36:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31597</guid>
		<description>I guess you can replace it with the following, and this isn&#039;t limited to 10 arguments:

&lt;code&gt;function DeferCall() {
	if (arguments.length == 0) {
		return null;
	}
	var args = arguments;
	// ... some stuff ...
	var fn = args.shift();
	fn.apply(args);
}&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I guess you can replace it with the following, and this isn&#8217;t limited to 10 arguments:</p>
<p><code>function DeferCall() {<br />
	if (arguments.length == 0) {<br />
		return null;<br />
	}<br />
	var args = arguments;<br />
	// ... some stuff ...<br />
	var fn = args.shift();<br />
	fn.apply(args);<br />
}</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: emailtoid.net/i/b172417b/</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31596</link>
		<dc:creator>emailtoid.net/i/b172417b/</dc:creator>
		<pubDate>Fri, 21 Nov 2008 17:49:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31596</guid>
		<description>&lt;code&gt;var i=0;
var exec_statement = &quot;fn(&quot;;
for(i=0;i&lt;args.length-1;i++) {
	exec_statement += &quot;args[&quot;+i+&quot;],&quot;;
}
if (i&lt;args.length) {
	exec_statement+=&quot;args[&quot;+i+&quot;]);&quot;;
} else {
	exec_statement+=&quot;);&quot;;
}
return eval(exec_statement);&lt;/code&gt;


Bertrand Le Roy: this took me ten seconds to come up with and I&#039;ve never written a line of javascript in my life.  You&#039;re telling me this wouldn&#039;t work in IE5?  I find that hard to believe.</description>
		<content:encoded><![CDATA[<p><code>var i=0;<br />
var exec_statement = "fn(";<br />
for(i=0;i&lt;args.length-1;i++) {<br />
	exec_statement += "args["+i+"],";<br />
}<br />
if (i&lt;args.length) {<br />
	exec_statement+="args["+i+"]);";<br />
} else {<br />
	exec_statement+=");";<br />
}<br />
return eval(exec_statement);</code></p>
<p>Bertrand Le Roy: this took me ten seconds to come up with and I&#8217;ve never written a line of javascript in my life.  You&#8217;re telling me this wouldn&#8217;t work in IE5?  I find that hard to believe.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: me.yahoo.com/cody.rioux</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31595</link>
		<dc:creator>me.yahoo.com/cody.rioux</dc:creator>
		<pubDate>Fri, 21 Nov 2008 14:52:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31595</guid>
		<description>Why would they bother detecting ie5 or not for the hack? They have to write it one way or another and it works fine in all the newer browsers. Writing detection and then the elegant code for newer browsers would just be writing more code than they need to.</description>
		<content:encoded><![CDATA[<p>Why would they bother detecting ie5 or not for the hack? They have to write it one way or another and it works fine in all the newer browsers. Writing detection and then the elegant code for newer browsers would just be writing more code than they need to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: emailtoid.net/i/09f9a6b7/</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31592</link>
		<dc:creator>emailtoid.net/i/09f9a6b7/</dc:creator>
		<pubDate>Fri, 21 Nov 2008 03:02:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31592</guid>
		<description>Really nice one !</description>
		<content:encoded><![CDATA[<p>Really nice one !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bertrand Le Roy</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31586</link>
		<dc:creator>Bertrand Le Roy</dc:creator>
		<pubDate>Wed, 19 Nov 2008 21:10:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31586</guid>
		<description>True.</description>
		<content:encoded><![CDATA[<p>True.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron N.</title>
		<link>http://www.clientcide.com/jsexamples/todays-javascript-wtf/comment-page-1/#comment-31585</link>
		<dc:creator>Aaron N.</dc:creator>
		<pubDate>Wed, 19 Nov 2008 19:03:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.clientcide.com/?p=492#comment-31585</guid>
		<description>Even if that&#039;s the case, they obviously have the ability to detect the difference between ie5 and other browsers (as they do so in the script above). If they wanted to add support to ie5 they could do this hacky work for ie5, but use apply for everything else.</description>
		<content:encoded><![CDATA[<p>Even if that&#8217;s the case, they obviously have the ability to detect the difference between ie5 and other browsers (as they do so in the script above). If they wanted to add support to ie5 they could do this hacky work for ie5, but use apply for everything else.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
