title: generic memoization approach in Javascript
body: <p>I understand that a number of generic memoized approaches rely on stringifying the argument list and using that as a key. E.g. as in:</p>
  
  <pre><code>Function.prototype.memoized = function() {
      this._values = this.values || {};
      var fn = this;
      return function() {
          var key = JSON.stringify( Array.prototype.slice.call(arguments) );
          if (fn._values[key]===undefined) {
              fn._values[key]=fn.apply(this, arguments);
          }
          return fn._values[key];
      };
  };
  </code></pre>
  
  <p>This obviously fails when one tries to memoize a "member function" since one would have to also JSON-stringify the context as well, i.e. treat it as an implicitly passed parameter. But that wouldn't work very well when the context is the global object or something equally deep or subject to change in various ways not related with the function itself.</p>
  
  <p>But even if we stick to non-"member functions" it may not always be possible to complete strigify the passed arguments list, right?</p>
  
  <p>Three questions:</p>
  
  <ol>
  <li>do I understand correctly that memoizing member functions in a generic way is non-sensical?</li>
  <li>do I understand correctly that memoizing even non-member functions in a generic way is also impossible due to the inability / impracticability to fully stringify any conceivable argument list?</li>
  <li>if 2 holds, then why do so many books and blogs try to define a generic <code>memoize</code> function in Function.prototype ? What's the point?</li>
  </ol>