title: Can I perfectly clone any ordinary object?
body: <p>I want to write a <code>cloneDeep</code> function that clones any JS object. There are two distinct problems here:</p>
  <ol>
  <li>Self references.</li>
  <li>Exotic objects.</li>
  </ol>
  <p>I want to focus on the latter. Exotic objects in ECMAScript are listed in this section: <a href="https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-built-in-exotic-object-internal-methods-and-slots" rel="nofollow noreferrer">10.4 Built-in Exotic Object Internal Methods and Slots</a>. There, it mentions exotic objects like strings, bound functions, Arrays etc. Specifically, it does not mention <code>RegExp</code>.</p>
  <p>So, my expectation was that given <code>RegExp</code> is an ordinary object, if I copy all its own properties (enumerable and non-enumerable) and its prototype, it will behave like the source <code>RegExp</code> object. But that is not true: it fails when I try to access the getter <code>regex.source</code> by explicitly saying it is not a <code>RegExp</code> object.</p>
  <p>Digging further, I found that some user-inaccessible internal slots exist in ECMAScript for various objects only to be accessible through their constructors.</p>
  <p>This leads me to believe either of the two is true:</p>
  <ol>
  <li><code>RegExp</code> is also an exotic object somehow.</li>
  <li>It is an ordinary object but there is some other state I did not copy.</li>
  </ol>
  <p>Which one of these is true? Because I am not able to wrap my head around an ordinary object with object-specific internal slots.</p>