An experiment using an object literal based class definition pattern

Allen Wirfs-Brock allen at
Tue Aug 9 12:57:59 PDT 2011

On Aug 8, 2011, at 10:40 PM, Brendan Eich wrote:

> On Aug 8, 2011, at 10:24 PM, Allen Wirfs-Brock wrote:
>>>> class superclass <| subclass () {
>>>> }
>>> That's so backward from other binding forms,
>> we don't really have a comparable binding form in ES.  The closest comparable are function declarations and they don't really provide any guidance for this problem.
> But class declarations in Python, Ruby, and other languages do provide guidance. None has this super < subclass ordering.

As Bob pointed out in a later message Smalltalk and self do, but I'm not arguing from that perspective.  I agree that the above is probably not a great binding form.  But it might not be a bad literal form:

const subclass = class superclass <| () { /* class body */}

with a strong internal parallel to 
  superclass <| function () {}

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.

> ...
>> 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 as subsequently wrote quite a bit of code.  Also, I also proposed the Class function to address that order issue, although I don't know whether I would actually use it. I generally don't find the exact pattern any more seemingly arbitrary or  difficult to use or remember than the various class syntaxes.  Try it, you may find it isn't so bad.


More information about the es-discuss mailing list