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

Eric Elliott eric at paralleldrive.com
Fri Mar 6 00:52:44 UTC 2015


>
>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150305/060a973f/attachment.html>


More information about the es-discuss mailing list