An experiment using an object literal based class definition pattern

Brendan Eich brendan at
Tue Aug 9 13:26:38 PDT 2011

On Aug 9, 2011, at 12:57 PM, Allen Wirfs-Brock wrote:

> Is it really necessary to add new binding forms or can we simply get along with let and const.  We Have already seen that there are issues with trying to hoist a class binding form.  Perhaps we would be better off simply not having any additional binding forms.

If class is not a binding form then we are not sugaring prototypal patterns that use function declarations.

Specifically, we're therefore taxing the extremely common case of binding a class name, by requiring a leading let C = or const C = in front of a class expression. This is punitive, it wouldn't do for functions (even though some advise it as always better style to write var f = function(){} -- they're mistaken).

Rather, the harmony:classes proposal supports class declarations and expressions, parallel to functions. Which is why some of us expected the former to hoist, but that's not essential.

>>> Yes, but we have no real evidence one way or the other that the usability  of <| and .{ is poor.  Mostly just assertions based upon minimal use.  
>> The usability of <| and .prototype. and the final .constructor (with .{ ... } or a ; after) is manifestly poor for defining a whole class. This is a no-brainer. Axel already got the order wrong!
> And I got it wrong the first time I tried to write it up.  But both Axel and I were experimenting with trying to find the right pattern rather than having been taught a specific pattern and how to use it.  After I figured it out, I haven't had any problem in remembering the exact pattern ...

Patterns cost. Peter Norvig's point about pattern-mongering being a sign of unfixed language bugs is one I agree with in general. There is a sunk cost fallacy in preferring patterns, especially ones with strung-out dots and punctuation and order requirements. This is ongoing cognitive load, scaled across all future users.

I do not think we're going to kill class syntax so easily.


More information about the es-discuss mailing list