Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve prototype when inherits #8

Open
sembrestels opened this issue Oct 19, 2013 · 0 comments
Open

Preserve prototype when inherits #8

sembrestels opened this issue Oct 19, 2013 · 0 comments

Comments

@sembrestels
Copy link

Look at this question in StackOverflow.

A problem of util.inheits is that previous prototype get lost. I think it would be fine if we preserve it in inherits module.

I improved this anwser. What do you think?

var util = require('util');

module.exports = {
    inherits : function(sub, sup, proto) {
        if (typeof proto === 'undefined') {
            proto = sub.prototype;
        }
        util.inherits(sub, sup);
            Object.keys(proto).forEach(function(key) {
                sub.prototype[key] = proto[key];
            });
        }
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant