title: JavaScript: clone a function
body: <p>What is a fastest way to clone a function in JavaScript (with or without its properties)?</p>
  
  <p>Two options coming to mind are <code>eval(func.toString())</code> and <code>function() { return func.apply(..) }</code>. But I am worried about performance of eval and wrapping will make stack worse and will probably degrade performance if applied a lot or applied to already wrapped.</p>
  
  <p><code>new Function(args, body)</code> looks nice, but how exactly can I reliable split existing function to args and body without a JS parser in JS?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Update:</strong>
  What I mean is being able to do</p>
  
  <pre><code>var funcB = funcA.clone(); // where clone() is my extension
  funcB.newField = {...};    // without affecting funcA
  </code></pre>