typeof null

Axel Rauschmayer axel at rauschma.de
Tue May 8 15:01:48 PDT 2012


One possibility is to make type() work for all values:

switch(type(x)) {
    case Primitive.null:
        ...
        break;
    case Primitive.string:
        ...
        break;
    case String:
        ...
        break;
}

That is, it would map primitive values to Primitive.* constants (or something similar, e.g. from a reflection API) and objects o to o.constructor.

On May 8, 2012, at 23:45 , David Herman wrote:

> On May 8, 2012, at 9:19 AM, Rick Waldron wrote:
> 
>> non-strict, non-opt-in:
>> 
>> typeof null === "null"; // false
>> 
>> implied opt-in:
> 
> Changing typeof null always seemed questionable to me in terms of value. It doesn't really give you significant new functionality, it just kinda seems "more sensible". But adding it would just make things *more* messy, for very little gain. Since we can't eliminate the old typeof semantics, we end up with the language having different semantics in different contexts.
> 
> And then once we moved to 1JS, it just seemed that much worse to have the variability, since the exact same code can have different meanings right near each other:
> 
>     var x = typeof null;
>     module Foo {
>         export var y = typeof null;
>     }
>     console.log(x)     // "object"
>     console.log(Foo.y) // "null"
> 
> It's just not worth it.
> 
> OTOH, we could pretty easily add a new library function:
> 
>     import type from "@std";
>     console.log(type(null)) // "null"
> 
> I'd support that.
> 
> Dave
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-- 
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/20120509/cf17b7f3/attachment.html>


More information about the es-discuss mailing list