Classes: suggestions for improvement

Allen Wirfs-Brock allen at
Tue Jun 14 15:13:49 PDT 2011

On Jun 14, 2011, at 3:00 PM, Axel Rauschmayer wrote:

> But in general: point taken. I do like the idea to use “factory”, but “class” might be close enough to people’s expectations that it works. What I find complicated is that what would be a class in, say, Python, is two constructs in JavaScript: (1) the constructor produces and initializes instances, (2) the prototype contains shared data.

In the class proposal the constructor function and the prototype are simply constituents parts of a single class declaration.  This definition actually turns into many objects in addition to the constructor function and the prototype.  For example, there are also all the individual method function objects.

The fact that a single language construct generates multiple runtime objects isn't unusual.  For example a Smalltalk class turns into a class object (roughly corresponding to the JS constructor), an instance method dictionary (roughly corresponding to the JS prototype), a metaclass object and a metaclass method dictionary (together, roughly corresponding to constructor properties), a class variable pool dictionary (roughly corresponding to any closure captured JS state that is shared by the constructor and instances), and at least one object per class or instance method.


More information about the es-discuss mailing list