UNPKG

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