How to fix the `class` keyword

Brendan Eich brendan at
Thu Mar 5 04:17:45 UTC 2015

Matthew Robb wrote:
> On the issue of calling class constructors, I would AT LEAST have 
> preferred implicit new on all calls to class constructors. Sure you 
> might get extra allocation weight but the way it stands now seems like 
> it could only lead to errors in people's assumptions...

An error caught by a throw is better than one that escapes as a 
silent-but-deadly (never mind allocation weight) difference in runtime 

In case it helps, the idea mooted for ES7 is that you'd add a "call 
handler" to the class for when it is invoked without `new`:

   class Point2D {
     constructor(x, y) { this.x = x, this.y = y; }
     [](x, y) { return new this.constructor(x, y); }

I used `this.constructor`, but of course using `Point2D` directly is 
possible. In that case, subclasses would have to override the 
`[]` method, which seems undesirable and easily avoided as 
shown above.

Bottom line, we don't want an implicit call handler in ES6. We need to 
get this right in ES7, and failing hard for now is the only way to be 


More information about the es-discuss mailing list