UNPKG

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