Christian C. Salvadó :
It looks similar to the Crockford's Object.create method, but this function is used to \"setup\" constructors.\n\nIt accepts two constructors as arguments, and it setups the prototype of the first one.\n\nLet me rename the cryptic variable names:\n\nfunction G(sub, super) {\n var F = function() { };\n F.prototype = super.prototype;\n sub.superLink = super.prototype;\n sub.prototype = new F();\n}\n\nfunction Super () {\n //...\n}\nSuper.prototype.member1 = 'superMember1';\n\nfunction Sub() {\n this.member2 = 'subMember2';\n}\n\nG(Sub, Super);\n\nnew Sub(); // Object { member2=\"subMember2\", member1=\"superMember1\"}\n\n\nEdit: The T 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 Pro JavaScript Design Patterns (page 43), with some additions, to prevent the constructor property to point to the wrong object:\n\nfunction extend(subClass, superClass) {\n var F = function() {};\n F.prototype = superClass.prototype;\n subClass.prototype = new F();\n subClass.prototype.constructor = subClass;\n\n subClass.superclass = superClass.prototype;\n if(superClass.prototype.constructor == Object.prototype.constructor) {\n superClass.prototype.constructor = superClass;\n }\n}\n\n\nSee also: \n\n\nJavaScript inheritance extend function\n",
2010-05-20T14:55:32