Ah, now I see the impetus for your other question (that's what I get for reading out of order).
I've had some similar questions recently and found myself deep in the rabbit hole of type theory...and I still don't have a crystal clear answer understanding. I'll take a swing below but take with an appropriately sized grain of salt... On Sun, Oct 23, 2011 at 2:07 AM, Axel Rauschmayer <[email protected]> wrote: > Sorry for bringing this up again, but I’m still having trouble with naming > things properly in JavaScript. > > - What do you call something that produces instances in JavaScript? A > class? A type? A constructor? Or is a constructor the implementation of a > type? > A constructor is a special kind of function in the language which produces instances of a given type, but you don't necessarily need a constructor to create an instance of a type -- at least w/ the nonstandard __proto__. Any time you instantiate an object with a specific prototype you've create an instance of a type. > - Are Date and RegExp built-in types? What do you call the value of the > global variable Date? Is new Date() an instance of a type or an instance of > a constructor? > Date is a type with a constructor. That which is returned by invoking the constructor is an instance of the Date type. > - 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. I've seen various terminology for the idea I think you're describing: datatype vs. compound type (IEC_11404), or simple type vs. complex type (XSD). But there's a whole lot of very related concepts. I've seen value type used on this list to describe simple primitives, which makes sense to me. The only thing I am sure of is that "typeof" is unfortunately named :) > - If instance factory B inherits from instance factory A, is B a subclass > of A? B a subtype of A? B a subconstructor of A? > There's no formal notion of a factory in the language, just a pattern. So none of the above? But if factory B returns instanceof B types, which are instanceof A, then B is a subtype of A. You could also call this a subclass relation, and people often do. This is fine currently as there's no formal notion of classes but might be confusing down the road -- this relationship may be declaratively expressed in a class hierarchy, or it might not, but it's essence would still be characterized by a link in a proto chain. There's a lot more to it formally, but javascript's type system -- the extensible bits available to us devs at least -- is limited to prototypes. Fundamentally, the ideas of value spaces, co and contravariance, Liskov Substitutability are all plenty relevant, you're pretty much on your own for enforcement. You could also say javascript's type lattice is pretty damn degenerate. This isn't a complaint though, just an observation -- I haven't heard too many people clamoring for static typing :) (I do think structural typing could be really useful but I have no idea how it could be introduced to the language unobtrusively.) > - Does a class literal (if it makes it into ES.next) define a class? Is a > class the implementation of a type? > My guess is a class literal *would* define a class -- anything else would be too confusing. But classes will never be the only game in town in defining the prototype hierarchy. > > Intuitively, it is clear how things work, but I find it difficult to be > precise when talking/writing about them. > > -- > Dr. Axel Rauschmayer > [email protected] > > home: rauschma.de > twitter: twitter.com/rauschma > blog: 2ality.com > > > > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

