(Weak){Set|Map} subclassing

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Dec 4 11:28:12 PST 2012

On Dec 4, 2012, at 10:57 AM, Erik Arvidsson wrote:

> On Tue, Dec 4, 2012 at 12:42 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> If you forget to do the super[create] call you don't get [[Prototype]] initialized.  However, if you leave out that super call you will also not allocate any superclass provided per instance state.   So, it would be buggy anyway.
> I was really hoping this would solve the Array subclass problem. Is this how you imagined it working then?
> Array.@@create = function() {
>   var newObj = [];
>   newObj.__proto__ = this.prototype;
>   return newObj;
> };

This indeed should solve the array subclassing problem.  You code is logically what Array.@@create needs to do.  In the spec. it will be expressed as a call to an abstraction operation that creates an exotic array object.  That call is parameterized with the [[Prototype]] value for the new instance.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121204/9362c664/attachment-0001.html>

More information about the es-discuss mailing list