How to fix the `class` keyword

Leon Arnott leonarnott at gmail.com
Thu Mar 5 04:40:30 UTC 2015


On Thu, Mar 5, 2015 at 5:46 AM, Brian Blakely <anewpage.media at gmail.com>
wrote:

> I just want public and protected properties, as well as data properties.
>
> After those, class and I are buddies.
>
>
 I observed on Twitter that data properties can be hammered in surprisingly
tersely, even without mixins:
```
let C = Object.assign(class {
  method1(){}
  method2(){}
  get accessor1(){}
  get accessor2(){}
}.prototype, {
  dataProperty: 1,
  dataProperty: 2,
}).constructor;
```
That is, if you don't mind them being enumerable, or that Symbol-keyed
properties aren't included. :P

I do, however, have a small personal grievance about the class syntax: why
doesn't it use commas to separate method and accessor properties? Consider
the disconnect. Object literal: commas. Array literal: commas. Class
literal: no commas. I appreciate that classes are not literals in quite the
same sense, in that they aren't really a list of properties that are
assigned to a single object, but it still seems quite un-Javascryptic to
have property after property with no commas between.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150305/6f2398ab/attachment.html>


More information about the es-discuss mailing list