<?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: A Better Javascript Memoizer</title>
	<atom:link href="http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/feed/" rel="self" type="application/rss+xml" />
	<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Wed, 25 Jan 2012 04:45:41 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Faster JavaScript Memoization For Improved Application Performance</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-71</link>
		<dc:creator>Faster JavaScript Memoization For Improved Application Performance</dc:creator>
		<pubDate>Mon, 19 Sep 2011 07:15:26 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-71</guid>
		<description>[...] been previously written about memoization and for further reading I recommend these pieces by John Hann and Nicholas Zakas. Douglas Crockford also briefly touched upon memoization in JavaScript: The Good [...] </description>
		<content:encoded><![CDATA[<p>[...] been previously written about memoization and for further reading I recommend these pieces by John Hann and Nicholas Zakas. Douglas Crockford also briefly touched upon memoization in JavaScript: The Good [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Test-Driven JavaScript Development &#124; Blog &#124; Discussion of Memoization</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-70</link>
		<dc:creator>Test-Driven JavaScript Development &#124; Blog &#124; Discussion of Memoization</dc:creator>
		<pubDate>Wed, 07 Sep 2011 20:38:59 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-70</guid>
		<description>[...] http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/. [...] </description>
		<content:encoded><![CDATA[<p>[...] <a href="http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/" rel="nofollow">http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/</a>. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A Better Javascript Un-memoizer. Part 1: Epic FAIL! &#124; Unscriptable.com</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-69</link>
		<dc:creator>A Better Javascript Un-memoizer. Part 1: Epic FAIL! &#124; Unscriptable.com</dc:creator>
		<pubDate>Wed, 28 Apr 2010 20:41:04 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-69</guid>
		<description>[...] my previous post, A Better Javascript Memoizer, some of you left some great feedback. (Thanks to all of you!) I think it&#8217;s because each of [...] </description>
		<content:encoded><![CDATA[<p>[...] my previous post, A Better Javascript Memoizer, some of you left some great feedback. (Thanks to all of you!) I think it&#8217;s because each of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uberVU - social comments</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-68</link>
		<dc:creator>uberVU - social comments</dc:creator>
		<pubDate>Sun, 31 Jan 2010 13:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-68</guid>
		<description>&lt;strong&gt;Social comments and analytics for this post...&lt;/strong&gt;

This post was mentioned on Twitter by major_code: http://tinyurl.com/cwomvm 
A Better Javascript Memoizer &#124; Unscriptable.com...</description>
		<content:encoded><![CDATA[<p><strong>Social comments and analytics for this post&#8230;</strong></p>
<p>This post was mentioned on Twitter by major_code: <a href="http://tinyurl.com/cwomvm" rel="nofollow">http://tinyurl.com/cwomvm</a><br />
A Better Javascript Memoizer | Unscriptable.com&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fogus</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-67</link>
		<dc:creator>fogus</dc:creator>
		<pubDate>Fri, 15 May 2009 17:18:44 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-67</guid>
		<description>You can make this work for functions with arity 0 by changing the last two lines to:

&lt;pre&gt;
    var arity = func.arity &#124;&#124; func.length;
    return memoizeArg(arity ? arity - 1 : 0);
&lt;/pre&gt;

-m</description>
		<content:encoded><![CDATA[<p>You can make this work for functions with arity 0 by changing the last two lines to:</p>
<pre>
    var arity = func.arity || func.length;
    return memoizeArg(arity ? arity - 1 : 0);
</pre>
<p>-m</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-66</link>
		<dc:creator>John H</dc:creator>
		<pubDate>Fri, 15 May 2009 03:48:29 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-66</guid>
		<description>Hey Simon,

On the surface, Nicolas&#039; implementation looks good, but it&#039;s not robust.  Here&#039;s why:

1. It adds properties to the function instance, f.&lt;/li&gt;
2. &lt;code&gt;args.toString()&lt;/code&gt; is not guaranteed to be unique for all combinations of arguments.

Regarding the first point, any general-purpose function should avoid interfering with other code as much as possible.  By assigning properties to the function instance, you have limited the calling code from using a similarly-named property on the function instance.  This may seem like a minor point, but if all general-purpose functions worked this way, we&#039;d eventually encounter conflicts &#8212; and this would result in some really nasty debugging sessions.

The second point is much more important.  All Javascript property names must be strings, so the array is serialized to a string when it is used as a property name (&lt;code&gt;f.memoized[args]&lt;/code&gt;).  In Javascript, Arrays serialze to a CSV-like representation.  For example, [1, 2, 3, &#039;foo&#039;] will serialize to &quot;1,2,3,foo&quot;.  This becomes a problem when objects are introduced &#8212; or even strings containing commas.  Here&#039;s what you&#039;d get when you pass the following arguments:

[1, &#039;commas,are,in,here&#039;, {foo: &#039;bar&#039;}] &#8658; &quot;1,commas,are,in,here,[object Object]&quot;

Unfortunately, the following arguments yield the same exact property name when serialized:

[1, &#039;commas&#039;, &#039;are&#039;, &#039;in&#039;, &#039;here&#039;, {prop: &#039;val&#039;}] &#8658; &quot;1,commas,are,in,here,[object Object]&quot;</description>
		<content:encoded><![CDATA[<p>Hey Simon,</p>
<p>On the surface, Nicolas&#8217; implementation looks good, but it&#8217;s not robust.  Here&#8217;s why:</p>
<p>1. It adds properties to the function instance, f.<br />
2. <code>args.toString()</code> is not guaranteed to be unique for all combinations of arguments.</p>
<p>Regarding the first point, any general-purpose function should avoid interfering with other code as much as possible.  By assigning properties to the function instance, you have limited the calling code from using a similarly-named property on the function instance.  This may seem like a minor point, but if all general-purpose functions worked this way, we&#8217;d eventually encounter conflicts &mdash; and this would result in some really nasty debugging sessions.</p>
<p>The second point is much more important.  All Javascript property names must be strings, so the array is serialized to a string when it is used as a property name (<code>f.memoized[args]</code>).  In Javascript, Arrays serialze to a CSV-like representation.  For example, [1, 2, 3, 'foo'] will serialize to &#8220;1,2,3,foo&#8221;.  This becomes a problem when objects are introduced &mdash; or even strings containing commas.  Here&#8217;s what you&#8217;d get when you pass the following arguments:</p>
<p>[1, 'commas,are,in,here', {foo: 'bar'}] &rArr; &#8220;1,commas,are,in,here,[object Object]&#8221;</p>
<p>Unfortunately, the following arguments yield the same exact property name when serialized:</p>
<p>[1, 'commas', 'are', 'in', 'here', {prop: 'val'}] &rArr; &#8220;1,commas,are,in,here,[object Object]&#8220;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-65</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Thu, 14 May 2009 13:58:07 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-65</guid>
		<description>The most elegant example I have ever seen is:

&lt;pre&gt;
function memoize(f) {
  return function () {
      var args = Array.prototype.slice.call(arguments);
      f.memoized = f.memoized &#124;&#124; {};
      return (args in f.memoized) ?
        f.memoized[args] :
        f.memoized[args] = f.apply(this, args);
  };
}
&lt;/pre&gt;
Courtesy of http://blog.thejit.org/</description>
		<content:encoded><![CDATA[<p>The most elegant example I have ever seen is:</p>
<pre>
function memoize(f) {
  return function () {
      var args = Array.prototype.slice.call(arguments);
      f.memoized = f.memoized || {};
      return (args in f.memoized) ?
        f.memoized[args] :
        f.memoized[args] = f.apply(this, args);
  };
}
</pre>
<p>Courtesy of <a href="http://blog.thejit.org/" rel="nofollow">http://blog.thejit.org/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2009-05-12 &#124; hooker headers</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-64</link>
		<dc:creator>links for 2009-05-12 &#124; hooker headers</dc:creator>
		<pubDate>Thu, 14 May 2009 01:53:45 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-64</guid>
		<description>[...] A Better Javascrip&amp;#116&amp;#32&amp;#77emoizer Yes, memoization is a neat concept. But wh&amp;#121&amp;#32&amp;#117se it rather than just hand-coded caching mechanis&amp;#109&amp;#115&amp;#63 It’s easy enough to write a caching routine, ri&amp;#103&amp;#104&amp;#116? Here are [...] </description>
		<content:encoded><![CDATA[<p>[...] A Better Javascrip&#116&#32&#77emoizer Yes, memoization is a neat concept. But wh&#121&#32&#117se it rather than just hand-coded caching mechanis&#109&#115&#63 It’s easy enough to write a caching routine, ri&#103&#104&#116? Here are [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oslo Mosquito raid &#187; Paris–Harrington theorem</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-63</link>
		<dc:creator>Oslo Mosquito raid &#187; Paris–Harrington theorem</dc:creator>
		<pubDate>Tue, 12 May 2009 23:25:35 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-63</guid>
		<description>[...] A Better Javascript Memoizer &#124; Unscriptable.com [...] </description>
		<content:encoded><![CDATA[<p>[...] A Better Javascript Memoizer | Unscriptable.com [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2009-05-12 &#171; boblog</title>
		<link>http://unscriptable.com/2009/05/01/a-better-javascript-memoizer/#comment-62</link>
		<dc:creator>links for 2009-05-12 &#171; boblog</dc:creator>
		<pubDate>Tue, 12 May 2009 10:18:17 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-62</guid>
		<description>[...] A Better Javascript Memoizer Yes, memoization is a neat concept. But why use it rather than just hand-coded caching mechanisms? It’s easy enough to write a caching routine, right? Here are a few good reasons: [...] </description>
		<content:encoded><![CDATA[<p>[...] A Better Javascript Memoizer Yes, memoization is a neat concept. But why use it rather than just hand-coded caching mechanisms? It’s easy enough to write a caching routine, right? Here are a few good reasons: [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

