>> Is it a good idea to overload this operator? >> >> 1. class objectExemplar: “turn the `objectExemplar` into a class” >> 2. class obj: “get the class of obj” >> >> I would give operator #2 the name `classof` and let `class` only return the >> own property value of `constructor`. > > I'm not over-loading the class operator. I the above I was simply pointing > out that this is what the operator I defined does in those circumstances.
OK. Overloading might have been the wrong term – it is the same implementation. I meant semantic overloading: two semantically different roles, performed by the same operator (see below). > The concept of a constructor function being the "class" of an object is one > of those things that has been around JS apparently from the beginning. It > just didn't have a suggestively named operator. However an object is > instantiated, this operator is simply reporting that the "class"of the object > whatever is accessible as the object's "constructor". So you don’t think the two roles clash semantically? (1) “Turn an object exemplar into a class” versus (1) “get the class of an object”. Both are definitely useful! But that they can be performed by the same operator seems like a happy coincidence. If (1) was to be further refined, e.g., as Brendan suggested, by throwing an exception if an object exemplar does not have a "constructor" method then it seems both roles would drift further apart. I’m mainly arguing for a clear separation of concerns. -- 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

