Allowing super to use EvaluateConstruct, or "How do I inherit from Date?"

Brandon Benvie brandon at brandonbenvie.com
Mon Jan 7 08:38:08 PST 2013


Yeah, that's a better way to say what I (poorly) expressed. It's not that
EvaluateConstruct needs to again be called (this would cause multiple
allocations). Rather, the super call that arose directly from
EvaluateConstruct needs to pass its "constructness" onto the
SuperConstructor.


On Mon, Jan 7, 2013 at 11:35 AM, Erik Arvidsson <erik.arvidsson at gmail.com>wrote:

> On Sun, Jan 6, 2013 at 10:32 PM, Brandon Benvie
> <brandon at brandonbenvie.com> wrote:
> > Despite separating out @@create into a property of functions, which
> allows
> > allocation and setting of BuiltinBrand for subclasses, this still leaves
> > inheriting from most builtins just short of possible because they are
> > "construct sensitive". The new ES6 classes like Map, Set, WeakMap, and
> typed
> > arrays have been carefully designed so the constructor initializes
> `this`.
> > But this still leaves most of the existing builtins un-subclassable.
>
> I think you are making this sound worse than it is.
>
> What isn't working is that super in the constructor doesn't do what you
> expect. The following should work
>
> class MyArray extends Array {
>   constructor(...args) {
>     // Intentionally not doing the crazy one-arg-is-length-if-uint32
>     this.push(...args);
>   }
> }
>
> class MyDate extends Date {
>   constructor(..args) {
>     var temp = new Date(...args);
>     this.setTime(temp.getTime());
>   }
> }
>
> I agree that it will be confusing to most users and that we should try
> to make super in a constructor work for these cases.
>
> --
> erik
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130107/793c3fee/attachment-0001.html>


More information about the es-discuss mailing list