4 ms·
No, it's because JS doesn't expose (or at least didn't used to before ES5) it's prototype system, but instead provides a pseudo class-based overlay. The proper
by cygx 14y ago
No, it's because JS doesn't expose (or at least didn't used to before ES5) it's prototype system, but instead provides a pseudo class-based overlay.
The proper way to do inheritance in JS is
// Foo extends Bar
Foo.prototype = Object.create(Bar.prototype);
function Foo() {
Bar.call(this);
}
Before the introduction of Object.create, you either had to roll your own version, assigned a dummy instance of Bar to Foo.prototype (which is horribly wrong) or transferred methods manually from Bar.prototype to Foo.prototype, which is arguably more 'in the spirit' of JS1.0.
That's not how it's done in 'real' prototypal languages like Self or Io.