Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks similar to the Crockford's <code>Object.create</code> method, but this function is used to "setup" constructors.</p> <p>It accepts two constructors as arguments, and it setups the <code>prototype</code> of the first one.</p> <p>Let me rename the cryptic variable names:</p> <pre><code>function G(sub, super) { var F = function() { }; F.prototype = super.prototype; sub.superLink = super.prototype; sub.prototype = new F(); } function Super () { //... } Super.prototype.member1 = 'superMember1'; function Sub() { this.member2 = 'subMember2'; } G(Sub, Super); new Sub(); // Object { member2="subMember2", member1="superMember1"} </code></pre> <p><strong>Edit:</strong> The <code>T</code> property is simply used to know what is the "super" constructor of the sub one, I've seen this pattern on other places, like in the book <em>Pro JavaScript Design Patterns</em> (<a href="http://books.google.com/books?id=za3vlnlWxb0C&amp;lpg=PP1&amp;dq=Pro%20JavaScript%20Design%20Patterns&amp;pg=PA43#v=onepage&amp;q&amp;f=false" rel="nofollow noreferrer">page 43</a>), with some additions, to prevent the <code>constructor</code> property to point to the wrong object:</p> <pre><code>function extend(subClass, superClass) { var F = function() {}; F.prototype = superClass.prototype; subClass.prototype = new F(); subClass.prototype.constructor = subClass; subClass.superclass = superClass.prototype; if(superClass.prototype.constructor == Object.prototype.constructor) { superClass.prototype.constructor = superClass; } } </code></pre> <p>See also: </p> <ul> <li><a href="https://stackoverflow.com/questions/2686258/javascript-inheritance-extend-function">JavaScript inheritance extend function</a></li> </ul>
    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.
 

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