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

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


Also it's not just confusing. Arrays and Date can be jury rigged to
function correctly with the recent ES6 spec changes, as you demonstrated.
That still leaves it impossible to extend Boolean, Number, String, and
RegExp (leaving out Function on purpose since that's in a league of its own
and would depend on @@call being added) because they are construct
sensitive and have no post-creation way of mutating their internal value.





On Mon, Jan 7, 2013 at 11:38 AM, Brandon Benvie
<brandon at brandonbenvie.com>wrote:

> 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/841ec2d9/attachment.html>


More information about the es-discuss mailing list