Prototypes as the new class declaration

Axel Rauschmayer axel at rauschma.de
Tue Jun 14 23:59:21 PDT 2011


> From: Brendan Eich <brendan at mozilla.com>
> Date: June 15, 2011 7:59:34 GMT+02:00
> 
> This brings out a difference between your class-less proposal and classes, you've covered it but it may not pop out: you cannot call a class method cm via SkinnedMesh.cm()
> . Instead you must call SkinnedMesh.constructor.cm() or equivalent.
> 
> Probably this is unfixable. The prototype object named here by SkinnedMesh is a singleton containing a single constructor function. Properties of the prototype show up, unless shadowed, in instances via delegation. Properties of the constructor, if inherited as I show above, come from the super-constructor. But there are no classes, so talking about class methods (never mind the "static" misnomer) does not make sense.
> 
> Constructor methods and other constructor properties can be created, but naming them requires that .constructor component.


Wouldn’t you add a class method like this?

const SkinnedMesh = THREE.Mesh <| {
  cm: function() {
  }
  ...
};

Then it could be invoked as SkinnedMesh.cm() (which to me is what a class method is: there is a class named SkinnedMesh and it has a method cm()).

Furthermore, it would automatically be inherited:

const SkinnedMeshExtended = SkinnedMesh <| { ... }

Then the following class method could also be called:

SkinnedMeshExtended.cm()

Right?

-- 
Dr. Axel Rauschmayer

axel at rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110615/bd6bbc9d/attachment.html>


More information about the es-discuss mailing list