`super` and superclass constructor return values
Logan Smyth
loganfsmyth at gmail.com
Sat Oct 17 00:24:05 UTC 2015
Yup, correct. The value of the `this` binding is initialized to the result
of `[[Construct]]`, which will either be the parent constructor `this`
binding, or the explicitly returned value.
Relevant spec links:
Evaluating `super()`: (12.3.5.1)
http://www.ecma-international.org/ecma-262/6.0/#sec-super-keyword-runtime-semantics-evaluation
Returning a value from a constructor: (9.2.2 step 13.b)
http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-construct-argumentslist-newtarget
On Fri, Oct 16, 2015 at 2:24 PM, Eric Faust <efaust at mozilla.com> wrote:
> Hi Isiah,
>
> My understanding is that this should log "true". Class constructors may
> return any object they wish, and needn't return instances of the class.
>
> Hopefully, this will allow you to simplify.
>
> Thanks,
>
> Eric
>
> On Fri, Oct 16, 2015 at 2:02 PM, Isiah Meadows <isiahmeadows at gmail.com>
> wrote:
>
>> What should `this` be in class `B`? The value of `object` or an instance
>> of `B`? It's an edge case, but could simplify my code a little if it's the
>> former.
>>
>> ```js
>> const object = {}
>>
>> class A {
>> constructor() {
>> return object
>> }
>> }
>>
>> class B extends A {
>> constructor() {
>> super()
>> console.log(this === object)
>> }
>> }
>> ```
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151016/ec42c246/attachment-0001.html>
More information about the es-discuss
mailing list