title: Extending the function prototype
body: <p>I'm looking to be able to extend the function prototype in javascript (that is to say, add a function to all functions).
  The purpose is to convert it into a format for exchange between another language (namely ruby, which can only communicate through strings [in this particular setting]). I've already got a system so I can pass around other types by defining a <code>to_js</code> method on ruby objects and a <code>to_ruby</code> method on javascript objects, like so</p>
  
  <pre><code>Number.prototype.to_ruby = function () { return this.toString(); }
  </code></pre>
  
  <p>This is working for everything else I want it to, but not for functions. I <em>can</em> get it to work in chrome by doing the following:</p>
  
  <pre><code>_empty = function() {};
  _empty.__proto__.to_ruby = function () {
      return 'JSFunction.new(' + this.toString().to_ruby() + ')';
  };
  </code></pre>
  
  <p>But this does not work in IE (which is a requirement of the system).</p>
  
  <p>I know I have an object somewhere keeping a track of functions by an ID or similar, but I can't guarantee that they will be used with the same instance that created them.</p>
  
  <p>All else failing I could just write a function to special case deal with it (ie, <code>isFunction(instance) ? fn_to_ruby(instance) : instance.to_ruby()</code>, but I'd rather keep this model if possible.</p>