Summary: prototypes as classes
brendan at mozilla.com
Tue Jun 28 17:29:21 PDT 2011
On Jun 28, 2011, at 4:41 PM, Bob Nystrom wrote:
> From my view, JS-of-today is no less prototype-based than what Axel is proposing, it just wires things up a bit differently. Or is there something I'm missing?
Brendan here, you know, the idiot who perpetrated JS. You are not missing anything. I wired up functions as constructors with .prototype properties to mimic Java classes, and supported the new operator, from JS1.0 in 1995 on. I made JS prototypal but not Self-like (no copy message, no multiple parents, no prototypes-not-constructors).
So now that we've cleared this up ;-), can we agree that prototypes and closures rock, and that constructor functions are not going away?
If so, it seems to me the prototype-first idea is trying to roll a very large, still moving stone up a tall hill. Yes, you can use prototypes that way. Indeed nothing stops users of ES.next, assuming <| or whatever it'll be called, and super-in-object-initialisers, make it to the finish line.
But that may not suffice to get the cows off the classy path. It may just complicate new and instanceof, with few users benefiting. I claim we can do little to control the outcome in terms of adoption. The downrev browser problem, plus the classical OOP patterning in many devs' brains, count more than our exhortations.
Would it be a better world if JS had always named the prototype, wired up new C to use C.constructor, etc.? Maybe. But that road was not taken, and that makes all the difference.
More information about the es-discuss