Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a difference between instances and their constructors.</p> <p>When creating an object like <code>{a: 1}</code>, you're creating an instance of the <code>Object</code> constructor. <code>Object.prototype</code> is indeed available, and all functions inside that prototype are available:</p> <pre><code>var o = {a: 1}; o.hasOwnProperty === Object.prototype.hasOwnProperty; // true </code></pre> <p>But <code>Object.create</code> does something different. It creates an instance (an object), but inserts an additional prototype chain:</p> <pre><code>var o = {a: 1}; var p = Object.create(o); </code></pre> <p>The chain will be:</p> <pre><code>Object.prototype - o - p </code></pre> <p>This means that:</p> <pre><code>p.hasOwnProperty === Object.prototype.hasOwnProperty; // true p.a === o.a; // true </code></pre> <p>To get the prototype "under" an instance, you can use <code>Object.getPrototypeOf</code>:</p> <pre><code>var o = {a: 1}; var p = Object.create(o); Object.getPrototypeOf(p) === o; // true Object.getPrototypeOf(o) === Object.prototype; // true </code></pre> <p>(Previously, you could access an instance's prototype with <code>o.__proto__</code>, but this has been deprecated.)</p> <p>Note that you could also access the prototype as follows:</p> <pre><code>o.constructor === Object; // true </code></pre> <p>So:</p> <pre><code>o.constructor.prototype === Object.prototype // true o.constructor.prototype === Object.getPrototypeOf(o); // true </code></pre> <p>This fails for <code>Object.create</code>-created objects because they do not have a constructor (or rather, their constructor is <code>Object</code> and not what you passed to <code>Object.create</code> because the constructor function is absent).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload