1 | const _ = require('lodash');
|
2 |
|
3 |
|
4 | module.exports = function extend(protoProps, staticProps) {
|
5 | const Parent = this;
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const Child =
|
11 | protoProps && protoProps.hasOwnProperty('constructor')
|
12 | ? protoProps.constructor
|
13 | : function() {
|
14 | return Parent.apply(this, arguments);
|
15 | };
|
16 |
|
17 | Object.assign(Child, Parent, staticProps);
|
18 |
|
19 |
|
20 | Child.prototype = Object.create(Parent.prototype, {
|
21 | constructor: {
|
22 | value: Child,
|
23 | enumerable: false,
|
24 | writable: true,
|
25 | configurable: true
|
26 | }
|
27 | });
|
28 |
|
29 | if (protoProps) {
|
30 | Object.assign(Child.prototype, protoProps);
|
31 | }
|
32 |
|
33 |
|
34 | Child.__super__ = Parent.prototype;
|
35 |
|
36 |
|
37 |
|
38 | if (_.isFunction(Parent.extended)) Parent.extended(Child);
|
39 |
|
40 | return Child;
|
41 | };
|