Answers for "javascript inherit function"

-1

javascript inherit function

function inherit(c, p) {
        Object.defineProperty(c, 'prototype', {
            value: Object.assign(c.prototype, p.prototype),
            writable: true,
            enumerable: false
        });

        Object.defineProperty(c.prototype, 'constructor', {
            value: c,
            writable: true,
            enumerable: false
        });
    }
// Or if you want multiple inheritance

function _inherit(c, ...p) {
        p.forEach(item => {
            Object.defineProperty(c, 'prototype', {
                value: Object.assign(c.prototype, item.prototype),
                writable: true,
                enumerable: false
            });
        })

        Object.defineProperty(c.prototype, 'constructor', {
            value: c,
            writable: true,
            enumerable: false
        });
    }
Posted by: Guest on February-08-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language