Referencing `super`

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Aug 5 18:37:08 PDT 2014


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/20140805/ef535752/attachment.html>


More information about the es-discuss mailing list