title: How to clone an object with an arrow function in JavaScript?
body: <p>I have this snippet of JavaScript code:</p>
  
  <pre><code>class Foo {
      constructor() {
          this.b = 1;
          this.getB = () =&gt; { return this.b; };
      }
  }
  
  const normalFoo = new Foo();
  const clonedFoo = magicClone(normalFoo);
  
  clonedFoo.b = 5;
  
  console.log(clonedFoo instanceof Foo); // should be true
  console.log(clonedFoo.getB()); // should be 5
  </code></pre>
  
  <p>I'd like to know what I can replace <code>magicClone</code> with in order to get the desired result (e.g. a clone that respects arrow function binding).</p>
  
  <p>I'm fine with any sorts of terrible hacks and I'm also fine with solutions that work <em>most</em> of the time, as long as they work in this case. This is mostly for my edification :) </p>
  
  <hr>
  
  <p>Please don't close this question as a duplicate - cloning an object has been asked many times, but I couldn't find a single answer that does this. <code>Object.assign</code>, lodash's <code>cloneDeep</code>, jQuery's clone, etc all do not handle this case.</p>