On Nov 14, 2011, at 6:36 PM, Axel Rauschmayer wrote:
>> Given this meaning of "class" when testing a value, I'm not sure if we can
>> rescue the pun above by which we use the same operator to define a class. If
>> forced to choose only one of these two roles for the "class" keyword, I'd
>> prefer to use it only to define a class, not to test values. But having only
>> just noticed this discrepancy, I am also not sure we cannot rescue the pun.
>> Let's try.
>
> Is a dual role even necessary? Why not stick to just class declaration?
> Looking through the eyes of an outsider, class { ... } looks like a class
> declaration. Given that we already have typeof and instanceof, wouldn’t an
> outsider expect a name such as classof? Furthermore, if object exemplars and
> function exemplars are to exist in parallel. Then:
>
> function Foo() {};
> var f = new Foo();
> classof f === Foo // true
>
> let Foo = {};
> var f = new Foo();
This could succeed, due to 'constructor' inherited from Object.prototype. But,
it could fail if we require an own constructor, or at least an inherited one
whose value is a function object (or callable object if host) whose .prototpye
is the exemplar.
> classof f === Foo // true
If new Foo() throws, you won't reach here, and all is consistent.
/be
>
> The above would not hold for `class`.
>
> --
> Dr. Axel Rauschmayer
> [email protected]
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss