I found this. What does it do?
function G(a, b) {
var c = function() { };
c.prototype = b.prototype;
a.T = b.prototype;
a.prototype = new c;
}
- It looks very similar to Crockford’s Prototypal Inheritance in JavaScript.
- Stackoverflow: What is happening in Crockford’s object creation technique?.
It looks similar to the Crockford’s
Object.createmethod, but this function is used to “setup” constructors.It accepts two constructors as arguments, and it setups the
prototypeof the first one.Let me rename the cryptic variable names:
Edit: The
Tproperty 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 theconstructorproperty to point to the wrong object:See also: