I noted some open issues on "Classes with Trait Composition"

Axel Rauschmayer axel at rauschma.de
Thu May 19 12:40:32 PDT 2011

> Yes, we've talked about this. One of the issues I don't know how to resolve is if we want to allow the specification of class properties aka statics

This is a somewhat orthogonal issue:

Currently the implementation of a type is a constructor function. This always felt slightly odd to me, because the prototype seems the more obvious choice. Then instanceof would be simpler. Furthermore, type properties (class properties) would make more sense and could additionally be inherited from supertype to subtype (use case: a root type implements a method for subtyping that can be applied to itself to create the first subtype).

The changes would be as follows:

(1) Allow |new| not just for functions, but also for "type objects". The type object itself would be the prototype of each newly created instance, instance data would be added in a special method (e.g. "constructor" or "new").
(2) Allow "type objects" to be the rhs for instanceof (in addition to function). That is, if the rhs of instanceof is an object, look for it in the prototype chain.

Has this been considered?

Then (the similar) "classes" (as syntactic sugar for constructor functions etc.) would maybe not be needed. Still missing is convenient subtyping

The remaining missing functionality is subtyping, but that could be added as an API (let me know if I should give an example, it would look a lot like YUI, but with less impedance mismatch).

Dr. Axel Rauschmayer

axel at rauschma.de

home: rauschma.de
blog: 2ality.com

More information about the es-discuss mailing list