I think they are equivalent but I’m not sure:
var __extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key)) child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
};
And
var __extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key)) child[key] = parent[key];
}
child.prototype = parent.prototype;
child.prototype.constructor = child;
child.__super__ = parent.prototype;
return child;
};
Both functions extend the
child(function) object with all properties of theparentobject, and they set the__super__property. Then the differences begin:This code creates a prototype object for
childwhich inherits fromparent.prototype. It is an old version of whatObject.create()does. This is the classical JavaScript inheritance pattern.This code is crap. It sets the
child‘s prototype object toparent.prototype, but forgets right in the next line that now both properties point to the same object (child.prototype === parent.prototype). Therefore,parent.prototype.constructor === childandchild.__super__ === child.protoype– urgh.