UNPKG

1.31 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var mix_1 = require("./mix");
4var is_function_1 = require("./is-function");
5var extend = function (subclass, superclass, overrides, staticOverrides) {
6 // 如果只提供父类构造函数,则自动生成子类构造函数
7 if (!is_function_1.default(superclass)) {
8 overrides = superclass;
9 superclass = subclass;
10 subclass = function () { };
11 }
12 var create = Object.create ?
13 function (proto, c) {
14 return Object.create(proto, {
15 constructor: {
16 value: c
17 }
18 });
19 } :
20 function (proto, c) {
21 function Tmp() { }
22 Tmp.prototype = proto;
23 var o = new Tmp();
24 o.constructor = c;
25 return o;
26 };
27 var superObj = create(superclass.prototype, subclass); // new superclass(),//实例化父类作为子类的prototype
28 subclass.prototype = mix_1.default(superObj, subclass.prototype); // 指定子类的prototype
29 subclass.superclass = create(superclass.prototype, superclass);
30 mix_1.default(superObj, overrides);
31 mix_1.default(subclass, staticOverrides);
32 return subclass;
33};
34exports.default = extend;
35//# sourceMappingURL=extend.js.map
\No newline at end of file