> - 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;
o1.foo = 123;
console.log(o2.foo); // 123
http://www.2ality.com/2011/03/javascript-values-not-everything-is.html
> 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 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/20111023/6a27bf81/attachment-0001.html>