Discussion

The Ways of Javascript Inheritance

Hey Hacker News! Lets talk about prototypal inheritance in JS!

What's the best way of doing it from a code reusability standpoint?

What's the best way of doing it from a time to create instance standpoint?

What's the best way of doing it from memory footprint standpoint?

Of the ways I've seen and tried, John's method seems the easiest to use: http://ejohn.org/blog/simple-javascript-inheritance/

But I hate that it has to loop through every property every time you extend a prototype.

Most inheritance patterns I've seen need to have the original prototype cloned or instantiated in order extend a new prototype safely. Is there a way to do it that allows all instances at all levels of the inheritance chain to still share the same common methods in memory where they aren't overridden?

Thanks!

8 points brittonrt 13 years ago 2 comments

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton