2 ms·
> 1) Prototypical inheritance is different from classical inheritance. This may be true, but JavaScript's flavor of prototypal inheritance is much closer to cl
by munificent 15y ago
> 1) Prototypical inheritance is different from classical inheritance.
This may be true, but JavaScript's flavor of prototypal inheritance is much closer to classical than it is to pure Self-style prototype delegation.
In Self, you make new instances by taking an existing object and cloning it. That creates a new object that delegates directly to the one you clone from.
In a class-based language, you make new instances by invoking a constructor, which is often a method on some other object that represents the class. That creates a new instance which shares a set of methods that all other objects created from that constructor share.
Which of those sounds more like JS? JS by virtue of having constructors and `prototype` already is 90% of the way to being class-based. It just lacks the syntax to make that pleasant to work with.
- MatthewPhillips 15y agoIn JS you share the prototype. It's dishonest to say you share the methods. Of course in most instances you only want to share the methods as sharing objects and arrays isn't often useful, but that's the way JS works. In a classical language the methods are shared and the non-function properties are copied. I would qualify this as a more than 10% difference.