Must built-in prototypes also be valid instances? (Was: Why DataView.prototype object's [[Class]] is "Object"?)

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Oct 2 09:07:52 PDT 2012


On Oct 1, 2012, at 4:08 PM, Domenic Denicola wrote:

> On Oct 1, 2012, at 18:58, "Brendan Eich" <brendan at mozilla.org> wrote:
> 
>> I am warming up to the way CoffeeScript does things -- not the translation scheme, __extends, __super__ -- rather, the plain Object instance created as C.prototype that has B.prototype as its [[Prototype]] but has shadowing 'constructor' set to C.
> 
> If I'm understanding correctly, this would be the same as
> 
> C.prototype = Object.create(B.prototype);
> C.prototype.constructor = C;
> 
> which I thought was the "recommended" approach (although by who or where, I admit I can't quite pinpoint). Am I on the right track? And can anyone else comment on the commonality or recommendedness of this pattern, to see if we're paving the right cow paths?
> 

This is essentially how ES6 classes get wired up.  Actually what they do is closer to:

      
let tempProto = Object.create(B.prototype);
tempProto.constructor = function (<constructor params>) {<constructor body>);
tempProto.constructor.__proto__ = B;
tempProto.constructor.prototype = tempProto;
C=tempProto.constructor;


        


More information about the es-discuss mailing list