title: Deep clone a function in javascript
body: <p>I have an object of objects:</p>
  
  <pre><code>nestedObj = {obj1:
  {cat:'thing1', 
   scale: d3.scaleSequential(d3.interpolateGreens)},
   ...
  }
  </code></pre>
  
  <p>And then I iterate over an array of things to create objects that are otherwise duplicative:</p>
  
  <pre><code>things = ['thing1','thing2',...]
  // A loop that creates:
  nestedObj.obj2 = Object.assign({},nestedObj.obj1,{cat:thing2}}
  </code></pre>
  
  <p>Then later in my code, I set properties of each function iteratively:</p>
  
  <pre><code>Object.keys(nestedObj)forEach(function(key){
   nestedObj[key].scale().domain([0,number])
  }
  </code></pre>
  
  <p>Which results in obj1.scale being overwritten by obj2.scale, I think because the function is a shallow copy. <code>jQuery.extend(true)</code> and <code>JSON.parse(JSON.stringify())</code> don't seem to work. Is there any way around this without changing my general order of operations?</p>
  
  <p>Thank you!</p>