title: How to clone a JavaScript object including getters and setters?
body: <p>In a project I'm working on, I need to clone an object to a variable.</p>
  <p>I first tried - what seemed to be the most obvious solution - to do <code>var obj2 = obj1</code>, however I soon realized this makes <code>obj2</code> <em>refer</em> to <code>obj1</code>, so whenever I set a property in <code>obj2</code>, the property is updated in <code>obj1</code>, too. Well, I can't have that.</p>
  <p>So, I started searching around for ways to clone a object in JavaScript - I found multiple solutions for this, mainly <code>var obj2 = JSON.parse(JSON.stringify(obj1))</code> - but that didn't keep all getters and setters I had defined for my object!</p>
  <p>The now most obvious solution to me seems to firstly use the JSON trick above to make <code>obj2</code> have all of <code>obj1</code>'s properties, then loop through all of the objects getters and setters and add them back using <code>Object.defineProperty()</code>, but I have yet to find a way to get all getters/setters of an object.</p>