javascript inherit function

Solutions on MaxInterview for javascript inherit function by the best coders in the world

showing results for - "javascript inherit function"
Nais
26 Apr 2018
1function inherit(c, p) {
2        Object.defineProperty(c, 'prototype', {
3            value: Object.assign(c.prototype, p.prototype),
4            writable: true,
5            enumerable: false
6        });
7
8        Object.defineProperty(c.prototype, 'constructor', {
9            value: c,
10            writable: true,
11            enumerable: false
12        });
13    }
14// Or if you want multiple inheritance
15
16function _inherit(c, ...p) {
17        p.forEach(item => {
18            Object.defineProperty(c, 'prototype', {
19                value: Object.assign(c.prototype, item.prototype),
20                writable: true,
21                enumerable: false
22            });
23        })
24
25        Object.defineProperty(c.prototype, 'constructor', {
26            value: c,
27            writable: true,
28            enumerable: false
29        });
30    }