super() call in methods

Bergi a.d.bergi at
Tue Dec 16 13:18:55 PST 2014

I've just read the spec draft 
<> on the super 
keyword to answer a StackOverflow question 

 From what I understood, it's currently not possible call a super method 
using only `super()`, contrary to common (my?) intution. A quick web 
search shows that other people think similar: (with a 2013 update):
| Super-references (including super-calls) are a feature of ECMAScript | 
6 which allows one to write describe() much more succinctly:
|     Employee.prototype.describe = function () {
|         // super() is an abbreviation of super.describe()
|         return super()+" ("+this.title+")";
|     };
| Although they look similar, super and this are independent features.
| super means “I’m currently in a method – find the method that that
| method has overridden and apply it to the same instance that is
| presently active (i.e., this stays the same)”
| class LogView extends View {
|   render() {
|     var compiled = super();
|     console.log(compiled);
|   }
| }
| We first call super(). This calls the parent class' render() method,
| and returns the result. This means that the render method on the View
| class is first called, and the result is stored in the compiled
| variable.
| class Base {
|   say() {
|     console.log('base');
|   }
| };
| class Derived extends Base {
|   say() {
|     console.log('derived');
|     super();
|   }
| };
| let instance = new Derived;
| instance.say();

I've read <> and it seems 
that needing to call `super.describe()`/`super.render()`/`super.say()` 
is intended behaviour. I'm fine with that, as explicit is better than 
implicit and "finding the method with the same *name*" (or something 
like that) is overly complicated and maybe even ambiguous.

However, it seems that we need to communicate better that `super()` 
calls only work in constructors, and other functions that inherit from 
That seems to be the reason why the method name GetSuper*Constructor*() 
was chosen in the spec.
Yet, `super()` calls in plain methods would actually work! The method 
objects would inherit from `Function.prototype`, which is itself 
callable: a no-op function. This might lead to subtle bugs, where 
`super()` was intended to call the parent class's method, but does 
nothing - not even throwing an error!

Should an exception been thrown if the `func` returned by 
`GetSuperConstructor()` is `%FunctionPrototype%`?

Best regards,

PS: there's a typo in `GetSuperConstructor`: s/activeFuntion/activeFunction/

More information about the es-discuss mailing list