How JavaScript works: 3 types of polymorphism
blog.sessionstack.com
How JavaScript works: 3 types of polymorphism
1–10 of 52 posts
Re: How JavaScript works: 3 types of polymorphism
#2Re: How JavaScript works: 3 types of polymorphism
#3A person can play many roles, at the same time. Composition is better in this case. A person has many roles
Inheritance is better for types of legal parties though (see The Party Model). A person is a legal party. An company is an organisation is a legal party
Re: How JavaScript works: 3 types of polymorphism
#4I'd say inheritance is NOT a good use-case for Person / Employee A person can play many roles, at the same time. Composition is better in this case. A person has many roles Inheritance is better for types of legal parties though (see The Party Model). A person is a legal party. An company is an organisation is a legal party
Re: How JavaScript works: 3 types of polymorphism
#5Re: How JavaScript works: 3 types of polymorphism
#6The very title is kinda scary, in the context that everything was kind of hacked onto JS. While it's probably important to understand, the 'answer' I think, without being ham-fisted, is probably to use Typescript in most cases.
Just because this forum is called hacker news don’t get your expectations twisted. We’re only here to boost engagement for acquisitions and “growth hacking”
Re: How JavaScript works: 3 types of polymorphism
#7I'd say inheritance is NOT a good use-case for Person / Employee A person can play many roles, at the same time. Composition is better in this case. A person has many roles Inheritance is better for types of legal parties though (see The Party Model). A person is a legal party. An company is an organisation is a legal party
I like the Go's approach to that (taken from Oberon), and the Rust's system of traits.
In one large codebase I saw there was a rule to make classes either abstract (without implementation of key parts), or final. Everything else is done via interfaces and composition.
See https://en.m.wikipedia.org/wiki/Composition_over_inheritance
Re: How JavaScript works: 3 types of polymorphism
#8I'd say inheritance is NOT a good use-case for Person / Employee A person can play many roles, at the same time. Composition is better in this case. A person has many roles Inheritance is better for types of legal parties though (see The Party Model). A person is a legal party. An company is an organisation is a legal party
Re: How JavaScript works: 3 types of polymorphism
#9Re: How JavaScript works: 3 types of polymorphism
#10There is a lot of wrong in this article: inability to articulate what polymorphism is, misunderstanding of prototypes, bad JS practices (`var`, `.__proto__`), falsehoods on programming languages including JS itself, confusion around ECS, unfinished examples... I suspect the author is in the early stages of their learning journey and Dunning-Kruger is in full effect.