Prototypes as the new class declaration

Allen Wirfs-Brock allen at wirfs-brock.com
Mon Jun 20 04:06:50 PDT 2011


On Jun 20, 2011, at 11:25 AM, Axel Rauschmayer wrote:

>>> It seems to me it would occur when in an ObjectLiteral where a function expression is assigned as the initial value of a 'constructor'-named PropertyAssignment.
>> 
>> correct, whatever magic there is occurs as part of defining a "constructor" property as part of an object literal.  However, such things could still be wired up manually (most likely by somebody wanting to create procedural abstractions for class-like definitions.
> 
> Are you thinking along the lines of the following example?
>     var MyClass = class({ ... });

no, referring back to the example in my post that started this thread:

> const SkinnedMesh = THREE.Mesh <| {
>   constructor(geometry, materials) {
>     super.constructor(geometry, materials);
>  
>     this.identityMatrix = new THREE.Matrix4();
>     this.bones = [];
>     this.boneMatrices = [];
>     ...
>   }, 
>   update(camera) {
>     ...
>     super.update();
>   }
> }
the "constructor" function defined above would  be automatically created with a "prototype" property whose value is the containing object created by the object literal.  Put another way:           
     SkinnedMesh.constructor.prototype===SkinnedMesh
would evaluate to true

Allen


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


More information about the es-discuss mailing list