typeof null

Axel Rauschmayer axel at rauschma.de
Tue May 8 16:45:10 PDT 2012

> Constants? We don't need no stinking constants! :-P Manifest strings, a la typeof, are the natural and self-describing upgrade path, if we're talking typeof (see Subject).
> The Reflect namespace object is part of direct proxies, also populated in SpiderMonkey (not web-facing) by Reflect.parse to get an AST for a given source string. We could indeed put type-reflecting method(s) there but I'm loath to add manifest constants. What's wrong with strings?

Nothing – if it’s only about primitive values. But if you want to have something that is both Allen’s `class` operator (for objects) and `typeof` (for primitive values) then constants are the best solution (that I can think of). I’ve always thought that the distinction between typeof and instanceof was a bit artificial, it would be nice if we had something that unified both.

Or do you propose returning functions for objects and strings for primitives? E.g.:

switch(type(x)) {
    case "null":  // x is null
    case "string":  // typeof x === "string"
    case String:  // x instanceof String


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/c8ec535c/attachment-0001.html>

More information about the es-discuss mailing list