Referencing `super`

Domenic Denicola domenic at domenicdenicola.com
Tue Aug 5 20:20:39 PDT 2014


I sympathize; I have always found the fact that bare `super()` works to be confusing.
________________________________
From: Brett Andrews<mailto:brett.j.andrews at gmail.com>
Sent: ‎2014-‎08-‎05 23:09
To: Allen Wirfs-Brock<mailto:allen at wirfs-brock.com>
Cc: es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>
Subject: Re: Referencing `super`

Thanks for your response, Allen. I'm not sure what convincing I can do. To me it seems odd that `super()` is the same as `super.submit()` but `super` is not the same as `super.submit`, but perhaps to others that seems perfectly fine. An alternative to this suggestion would be `super()` should not be the same as `super.submit()`; and instead `super()` is either illegal or calls `constructor`.

Brett.


On Wed, Aug 6, 2014 at 11:37 AM, Allen Wirfs-Brock <allen at wirfs-brock.com<mailto:allen at wirfs-brock.com>> wrote:

On Aug 5, 2014, at 6:06 PM, Brett Andrews wrote:

Some differences/oddities I noticed between referencing and invoking `super`. I briefly discussed this with Erik Arvidsson at https://github.com/google/traceur-compiler/issues/1220. In essence, if you can invoke in two seperate ways, it seems logical that you should be able to reference in those two ways (super() ~= super.submit(); super != super.submit).

```
class ClientForm extends Form{
  submit() {
    super.submit(); // Invokes Form.submit
    let superSubmit = super.submit; // Reference to Form.submit
    superSubmit(); // Invokes, but `this` is now undefined; not sure if intended

just like:
        this.submit(); // Invokes ClientForm.submit
        let thisSubmit = this.submit;  //Reference to ClientForm.submit
        thisSubmit();   //invokes, but 'thts' in now undefined

This is how properties and method invocations work in JS.  All that the use of 'super' does is change the place the property lookup starts.  Otherwise 'super' is equivalent to 'this' in the above code.


    super(); // Invokes Form.submit
semantically equivalent to
         super.submit();
just a short cut


    let superSubmit2 = super; // Error: "Unexpected token ;"

in some languages, such a unqualified 'super' reference would be equivalent to 'this'.
We intentionally made it an error for that reason.  I perhaps could be convinced that it should mean the same as 'super.submit'.
But in that case,
    superSubmit2()
would still not be the same thing as
    super();
or
     super.submit();

Allen

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


More information about the es-discuss mailing list