Re: Terminology: types, constructors, classes, …

Axel Rauschmayer axel at
Sun Oct 23 09:01:49 PDT 2011

> - What about primitives?Are there primitive types and object types? Is the union of the two called just “types”?
> That seems to be how a lot of folks refer to them, but I think it's a little confusing. A primitive type is one that cannot be decomposed any further, so Object is a primitive type, and a Function is an object type.

Almost: a primitive is something that isn’t handled by reference. Object is therefore not a primitive type:
var o1 = new Object();
var o2 = o1; = 123;
console.log(; // 123

> The only thing I am sure of is that "typeof" is unfortunately named :) 

I now use the rule of thumb:
- typeof: use for primitives and to distinguish primitives from objects.
- instanceof: use for objects.

Obviously, typeof also works for checking for functions.

> You could also say javascript's type lattice is pretty damn degenerate.

Can you elaborate?

> (I do think structural typing could be really useful but I have no idea how it could be introduced to the language unobtrusively.)

Something like this?
    var Counter = { inc: "function", data: "number" };
    matchesInterface(anObject, Counter);

Dr. Axel Rauschmayer
axel at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list