The class operator: a bridge between object and function exemplers
Axel Rauschmayer
axel at rauschma.de
Mon Nov 14 13:15:25 PST 2011
> The class operator can prefix any UnaryExpression, not just object literals. That means that the class operator can be used to classify objects:
>
> if (class p === Point) ...
>
> Note that many object-oriented abstraction designers consider this for of class testing to be an anti-pattern.
>
> It also works with instances of the standard ES built-in constructors:
>
> if (class new Array(1,2,3,4) === Array) ... //this will be true
>
> so are these:
>
> if (class [1,2,3,4] === Array) ...
> if (class [].pop === Function) ...
Is it a good idea to overload this operator?
1. class objectExemplar: “turn the `objectExemplar` into a class”
2. class obj: “get the class of obj”
I would give operator #2 the name `classof` and let `class` only return the own property value of `constructor`.
--
Dr. Axel Rauschmayer
axel at rauschma.de
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111114/5e05a8be/attachment.html>
More information about the es-discuss
mailing list