The class operator: a bridge between object and function exemplers

Jake Verbaten raynos2 at gmail.com
Mon Nov 14 16:05:50 PST 2011


>
>    *UnaryExpression* :
>            *class* *UnaryExpression*
>            ...
>
> The semantics are:
>  1. if *UnaryExpression* is undefined or null, return the value of *
> UnaryExpression*.
>  2. Let *obj* be ToObject(*UnaryExpression*)
> 3. Return the result of calling the [[Get]] internal method of *obj* with
> argument 'constructor'
>
>
> Interesting, so 'constructor' will inherit from Object.prototype if
> missing from the exemplar. This means
>
> let Point = class {
>      x:0,
>      y,0
> };
>
> let p = new Point(1, 2);
>
> will result in p being constructed via the equivalent of new Number(1).
>

When you create a function, it has an automatically created prototype
object who has a constructor property defaulted to the original function.

Why would it be bad to augment the UnaryExpression after the class keyword
so that it has an empty constructor if it doesn't exist?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111115/752d4d7a/attachment.html>


More information about the es-discuss mailing list