Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This has everything to do with the <code>new</code> keyword. In JavaScript, <code>new</code> only works with functions (which are a special type of object).</p> <ul> <li><p>If you use <code>new</code> on just about any function, you will get an object back.</p> <pre><code>alert(typeof console.log); // function var dumb = new console.log(); // dumb is an object </code></pre></li> <li><p>The type of object you get back depends on that function's prototype object.</p> <pre><code>alert(typeof console.log.prototype); // object, any new objects created by the new keyword will be of this type. alert(typeof Function.prototype); // function, new objects are functions. alert(typeof new Function()); // function, see? alert(typeof (function(){})); // function, using literal syntax, equivalent </code></pre></li> <li><p>You may have noticed from above that <code>Function</code> itself is a function. In fact, all of the built-in constructors are functions (Function, Object, Number, Array, etc). Capitalization is just a convention to distinguish how you use a function.</p></li> </ul> <p>So to get back to your question, the author uses an empty Function object simply because it can be used as a constructor. Objects cannot. He then changes the constructor's prototype, so that it will return objects of that type.</p> <pre><code>Object.beget = function(o) { var F = new Function(); // now F can be used as a constructor. F.prototype = o; // All new objects F creates will be based on o. return new F(); }; </code></pre>
    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. 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.
    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