typeof symbol (Was: Sept 19 TC39 Meeting Notes)

Uli Riehm uli.riehm at metadea.de
Sat Sep 29 15:46:45 PDT 2012

I think typeof should be simplified, focusing more on instanceof: typeof 
should only return "undefined", "string", "number", "boolean" and "object".

var fn = function () { };
fn instanceof Function // true
fn instanceof Object // true

Because typeof returns a string it is never true for two different types, so 
instanceof is more detailed. Problems would be that Null, NotANumber, 
Infinity habe to be functions, so that a null can also be instanceof an 
Object and a NaN instanceof NotANumber Number Object. Using an Int64 
Function where the prototype is Number, we could also have an instanceof 
Int64 Number Object.

I'm also tweaking around instanceof in my article on 
http://metadea.de/V/default.aspx#V_construct_and_your_class ... please see 
how I'm creating 'class' functions, having real OOP in jS, using instanceof, 
featuring reflection using a V.Construction Object class info (that is also 
used for prototyping a base function) and an the implicit instanceOf and 
constructionOf functions. Without hacking around __proto__ .

However I'd like to say that in the part of "Why javaScript typeof operator 
should be deprecated" I didn't thought properly about primitives and the 
usage of the operators that my idea would completely break ;) So please read 
that part with this warning in mind, but there are also some thoughts on 
primitives that are boxed to Object.
To say simple what I need to change in the ...deprecated... part is, that 
typeof and primitives should keep, but the constructor and the primitives 
corresponding Object instances should be the way described.


More information about the es-discuss mailing list