How to fix the `class` keyword (Brendan Eich)

# Eric Elliott (10 years ago)

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; } [Symbol.call](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 [Symbol.call] 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 future-proof.

/be

Thanks Brendan. This is very helpful indeed! Where can I learn more about that solution?

I assume for backwards compatibility, this will not be default behavior, so we're going to have to remember to use this boilerplate with every class if we don't want them to be broken, right?

~ee

# Brendan Eich (10 years ago)

Eric Elliott wrote:

Thanks Brendan. This is very helpful indeed! Where can I learn more about that solution?

I know of this gist: gist.github.com/wycats/0bd8f14066e44ed7b90e. Cc'ing wycats.

I assume for backwards compatibility, this will not be default behavior, so we're going to have to remember to use this boilerplate with every class if we don't want them to be broken, right?

Some opt-in syntax will be required. Decorators (also on agenda) should minimize the overhead.