`super` and superclass constructor return values
# Eric Faust (10 years ago)
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,
# Logan Smyth (10 years ago)
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)
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)
www.ecma-international.org/ecma-262/6.0/#sec
What should
thisbe in classB? The value ofobjector an instance ofB? It's an edge case, but could simplify my code a little if it's the former.const object = {} class A { constructor() { return object } } class B extends A { constructor() { super() console.log(this === object) } }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) } } ``` -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151016/2c1b8681/attachment.html>