2 ms·
> I wonder how Javascript object system compare to Self, or similar language IO? It's limited, confusing and muddled, because the prototypal stuff was really t
by masklinn 7y ago
> I wonder how Javascript object system compare to Self, or similar language IO?
It's limited, confusing and muddled, because the prototypal stuff was really there for the ease of implementing an object system (until ES6 the prototype was the red-headed stepchild of the language standards-wise) and ctors were tacked on for familiarity with Java but actual inheritance support (actually supporting JS-level subtypes) was all half-assed and very confusing before ES6. Basically pre-ES6 it was a complete mess unless you used non-standard extensions (e.g. `__proto__`).
ES6 both dramatically surfaced the prototypal inheritance (Object.create, Object.getPrototypeOf, Object.setPrototypeOf, Object.defineProperty) and made it even more of an implementation detail of the "class" syntactic sugar.
Nowadays you can pretty much use JS as a class-based language… and most people do that because frankly it's not worth messing around with the underlying prototypal system, you'll just confuse both your colleagues and your editor.
- ChrisSD 7y agoI think you're mixing up your timelines. ES5 brought `Object.create` and other prototype helper methods. This was a heyday, of sorts, for JS as a prototypal language with Crockford and others trying to explain how prototypes differ from inheritance based classes. However even then the C++/Java model had become too well ingrained by that point, especially at certain very large tech companies. The `class` keyword was introduced in ES6, which is indeed a kludge on top of prototypes.
- masklinn 7y ago> I think you're mixing up your timelines. ES5 brought `Object.create` and other prototype helper methods. You’re right, I did. So the actual timeline was somewhat less dim than I remembered. > The `class` keyword was introduced in ES6, which is indeed a kludge on top of prototypes. I wouldn’t say that it’s a kludge. I’d anything it’s more of a realisation of the original vision of JavaScript (which you could fairly call a kludge): using a prototype system to underlie a langage approaching java semantics. Which may well be the dumbest way to approach it as you get the flexibility of a class-based system and the performances of a prototype-based system rather than the other way around, but at the same time JS’s prototype system was kneecapped from the start.