Skip to content

Proper way to do inheritance in nodejs #16

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

Closed
kkc opened this issue Oct 14, 2015 · 5 comments
Closed

Proper way to do inheritance in nodejs #16

kkc opened this issue Oct 14, 2015 · 5 comments

Comments

@kkc
Copy link

kkc commented Oct 14, 2015

Hi, all. I am new to nodejs.
I don't know if this is a right place to ask such simple question.

I should write the code that could run on browser side and server side.
I found out that I can use require('util').inherits to do inheritance thing in nodejs.
But if I want to let same code run on both client and server side,
how can I do for that? Thanks a lot !

@Trott
Copy link
Member

Trott commented Oct 14, 2015

One way to be able to use util.inherits() in the browser is to use browserify. I have not used webpack but it is also likely to supply util.inherits().

@kkc
Copy link
Author

kkc commented Oct 15, 2015

thanks a lot, I will try to learn how to use browserify!

@Fishrock123
Copy link

I'd suggest taking a look at the implementation of util.inherits(): https://github.com/nodejs/node/blob/master/lib/util.js#L734-L772

JavaScript uses what we call "prototypical inheritance", which is different than some other languages. You can probably find a lot of info by googling something like that. :)

@kkc
Copy link
Author

kkc commented Oct 26, 2015

@Fishrock123 thanks a lot, your suggestion is very helpful :)

@Knighton910
Copy link
Contributor

Closing for now, feel free to reopen.

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

4 participants