3 ms·
The trouble goes deeper than that. Prototypal inheritance in itself probably wouldn't be all that confusing for these people — it's actually a simpler concept t
by chc 15y ago
The trouble goes deeper than that. Prototypal inheritance in itself probably wouldn't be all that confusing for these people — it's actually a simpler concept than classical inheritance. The issue with JavaScript's object system is that it's downright convoluted.
AFAIK, Self is the progenitor of prototype-based OO. In Self, the way you create a new object is just `someObject copy`. You can dynamically change its prototype later if you want, too. But in traditional JavaScript, you can't do that. You want an object? You need a constructor. Instead of just cloning a prototype, you have to do the whole `function Foo() { blah blah.prototype = someObject blah blah }; myFoo = new Foo()` rigamarole, and there is no standard way to access an object's prototype.
JavaScript has finally got the equivalent of Self's object creation with Object.create, but that is pretty new — and the actual object system still has the whole wonky prototype/constructor/__proto__ mess behind the scenes.
- MatthewPhillips 15y agoObject.create doesn't have the constructor bit at all. Try for yourself, create an object from another using Object.create and see if the second is an instanceof the first (it's not).