« Return to Thread: typeof null

Re: typeof null

by rauschma :: Rate this Message:

| View in Thread

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
        ...
        break;
    case "string":  // typeof x === "string"
        ...
        break;
    case String:  // x instanceof String
        ...
        break;
}


Axel

-- 
Dr. Axel Rauschmayer



_______________________________________________
es-discuss mailing list
es-discuss@...
https://mail.mozilla.org/listinfo/es-discuss

 « Return to Thread: typeof null