Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>if (typeof Object.create !== 'function') { Object.create = function (o) { function F() {} F.prototype = o; return new F(); }; } var oldObject={prop:'Property_one' }; // An object var newObject = Object.create(oldObject); // Another object </code></pre> <p>In the above example we've created a new object <code>newObject</code> using <code>create</code> method which is a member function of <code>Object</code> object that we've added in the <code>Object</code> object earlier in our (Crockford's) example. So basically what it does is that, the <code>create</code> method declares a function <code>F</code>, an empty object <code>every function is a first class object in javascript</code> and then we've inherited the prototype of <code>o</code> (in that case <code>o</code> is also an object <code>oldObject</code> passed as the parameter of create method) and finally we've returned the new object (an instance of F) using <code>return new F();</code> to the variable <code>newObject</code>, so now <code>newObject</code> is an object that inherited the <code>oldObject</code>. Now if you write <code>console.log(newObject.prop);</code> then it'll output <code>Property_one</code> because our <code>newObject</code> object has inherited the <code>oldObject</code> and that's why we've got the value of <code>prop</code> as <code>Property_one</code>. this is known as prototypical inheritance.</p> <p><strong>You must pass an object as the parameter of <code>create</code> method</strong></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