The class operator: a bridge between object and function exemplers

Axel Rauschmayer axel at
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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list