title: Does Chrome retain each object's constructor?
body: <p>In Chrome's JavaScript console:</p>
  
  <pre><code>&gt; function create(proto) {
      function Created() {}
      Created.prototype = proto
      return new Created
    }
  undefined
  
  &gt; cc = create()
  Created {}
  
  &gt; cc
  Created {}
  </code></pre>
  
  <p><code>Created</code> is a function private to the <code>create</code> function; after <code>create</code> completes, there are no (known to me) references to <code>Created</code>. Yet Chrome can show the function's name at any time, starting from the object created by it. </p>
  
  <p>Chrome didn't achieve this by following the "naïve" approach:</p>
  
  <pre><code>&gt; cc.constructor
  function Object() { [native code] }
  
  &gt; cc.toString()
  "object [Object]"
  </code></pre>
  
  <p>and anyway, I didn't set <code>constructor</code> on the <code>proto</code> argument passed to <code>create</code>:</p>
  
  <pre><code>&gt; cc.__proto__.hasOwnProperty("constructor")
  false
  </code></pre>
  
  <p>One guess I had is that the JavaScript VM holds on to <code>Created</code> for the sake of the <code>instanceof</code> mechanism. It is said that <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof?redirectlocale=en-US&amp;redirectslug=JavaScript%2FReference%2FOperators%2Finstanceof" rel="noreferrer"><code>instanceof</code></a></p>
  
  <blockquote>
    <p>tests whether an object has in its prototype chain the prototype property of a constructor.</p>
  </blockquote>
  
  <p>But in the above code I typed <code>create()</code>, effectively passing <code>undefined</code> as prototype; consequently <code>Created</code> doesn't even have its <code>prototype</code> set to the actual <code>cc.__proto__</code>. We can verify this if we hack <code>create</code> to expose the <code>Created</code> function:</p>
  
  <pre><code>function create(proto) {
    function Created() {}
    Created.prototype = proto
    GlobalCreated = Created
    return new Created
  }
  </code></pre>
  
  <p>now let's type</p>
  
  <pre><code>&gt; cc = create()
  Created {}
  
  &gt; GlobalCreated
  function Created() {}
  
  &gt; GlobalCreated.prototype
  undefined
  
  &gt; cc instanceof GlobalCreated
  TypeError: Function has non-object prototype 'undefined' in instanceof check
  </code></pre>
  
  <h2>My questions (all closely related):</h2>
  
  <ol>
  <li><p>What exactly does Chrome's JavaScript engine retain to make that object presentation in the console work? Is it the constructor function, or just the function name?</p></li>
  <li><p>Is that retention needed for anything more substantial than console printout?</p></li>
  <li><p>What is the effect of such retention on memory consumption? What if, for example, the constructor function (or even its name) is abnormally huge?</p></li>
  <li><p>Is it just Chrome? I've retested with Firebug and Safari, their consoles don't present the object that way. But do they still retain the same data, for other possible purposes (e.g. due to a genuine concern inherent to a JavaScript VM)?</p></li>
  </ol>