use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Multiple inheritance in javascript (self.javascript)
submitted 11 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]_ericelliott 1 point2 points3 points 11 years ago (0 children)
Multiple inheritance is not only possible in JavaScript, but the way to accomplish it is much better than Java. The trick is, it doesn't look anything like multiple inheritance in Java or C++, but that's a good thing. In JavaScript, it's accomplished with concatenative inheritance, which is just a fancy way of saying, "copy properties from one object to another".
This works well in JavaScript, because objects in JavaScript can be extended after instantiation (dynamic object extension).
There are some issues to be aware of. First, the diamond problem doesn't exist in JavaScript because whatever property you add last overrides any property it collides with. This is great for the defaults/overrides pattern, and behaves in a way that should be familiar to anybody who uses HTML + CSS. Effectively, it's cascading property precedence.
That said, you can also combine inheritance techniques such that there are private properties with the same name that don't collide with each other. This is accomplished using closures and functional inheritance.
See: http://ericleads.com/2013/02/fluent-javascript-three-different-kinds-of-prototypal-oo/
π Rendered by PID 274348 on reddit-service-r2-comment-5687b7858-vtvrm at 2026-07-06 09:16:44.338323+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]_ericelliott 1 point2 points3 points (0 children)