2 ms·
I'm honestly really confused by this article, and would love if someone could clarify this for me (no pun intended). The author mentions that classical inherita
by pcthrowaway 12y ago
I'm honestly really confused by this article, and would love if someone could clarify this for me (no pun intended). The author mentions that classical inheritance is to be avoided and prototypal inheritance is one of the language's best features. Then he goes on to state that the constructor pattern is also to be avoided and suggests that this is something people use in an attempt to use JS in an object-oriented way.
Correct, me if I'm wrong, but using the constructor pattern (and new) in Javascript is the only real way to create an object that has a prototypal link to the constructor function's prototype. So what does this have to do with classical inheritance?
- raffomania 12y agoHow about using `Object.create` (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/create https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...)?
- esailija 12y agoYou can also use Object.create, __proto__ setter or a custom abstraction. However the constructor pattern is in practice used everywhere and I find nothing wrong with it, in fact in the next language version it will get first class syntax through the `class` construct. People need to accept that same keywords mean different things in different languages, just because Javascript `this` and `new` are not like Java `this` and new` doesn't make it better or worse.
- pcthrowaway 12y agoOk, but wouldn't Object.create be more useful for when you are trying to shoehorn classical inheritance into Javascript? I still don't understand why he's implying (if I'm reading correctly) that using constructors is bad because you end up with the gorilla-holding-banana-and-forest problem that (he argues) comes with classical inheritance.
- jimmaswell 12y agoThat gorilla-holding-banana-and-forest problem is more of a boogeyman than anything.