我的问题是从this question理解打字稿继承
启发这是打字稿继承代码
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
和我的简化版本,该版本
function extend(Destination, Base) {
function Hook() { this.constructor = Destination; }
Hook.prototype = Base.prototype;
var hook = new Hook();
Destination.prototype = hook;
};
,我画的图形represantation从here灵感:
您能否确认或更正图形表示?
我特别不明白这个部分:
function Hook() { this.constructor = Destination; }
你能告诉我如何继承与参数工作,并伴有例如
感谢您的回答,你说'指出它的构造函数在subType,以便当一个新的ctor()被创建它实际上创建一个新的subType.'。这点我不清楚。例如,从chrome控制台输入 –
:我声明subType'function subType(){this.a; alert(this.a);}'和ctor'函数ctor(){this.constructor = subType}',但是当我做'new ctor()'时,它不会弹出警报 –
@asdf_enel_hak您还需要链原型。仅靠构造函数是不够的 – series0ne