title: Javascript: better way to add dynamic methods?
body: <p>I'm wondering if there's a better way to add dynamic methods to an existing object. Basically, I am trying to assemble new methods dynamically and then append them to an existing function.</p>
  
  <p>This demo code works.</p>
  
  <pre><code>builder = function(fn, methods){
  
      //method builder
      for(p in methods){
          method = 'fn.' + p + '=' + methods[p];
          eval(method);
      }
  
      return fn;
  }
  test = {}
  test = builder(test, {'one':'function(){ alert("one"); }','two':'function(){ alert("two"); }'} );
  
  test.one();
  test.two();
  </code></pre>