New ES6 constructor features and semantics: Alternative 1 auto allocation in derived classes
September 17, 2014 ยท View on GitHub
Summary of revised semantics for super based references
- The semantics of super used as the base for a property access (eg, super.name or super[expr] have not changed.
- Requires that a [[HomeObject]] has been set for the function, either via a concise method definition or dynamcially using
toMethod. - Starts property lookup at [[Prototype]] of [[HomeObject]] value.
- Passes current this value.
- super without a property access qualifier is only allowed within a constructor: function defined using a FunctionDeclaration, FunctionExpression, a call to the Function constructor, or the
constructorConciseMethod within a class defintion. It is also allowed within an ArrowFunction within the body of any such a function. - In any other function, the occurrance of super without a property access qualifier is an early syntax error.
- This is a change. Previously an unqualifed super could occur any where and was implicitly a propety access using the [[MethodName]] value as the property key.
- Within a constructor an unqualifed super may only be used in one of these forms:
- NewExpression: new super
- NewExpression: new super Arguments
- CallExpression: super Arguments
- Within a constructor an unqualified super reference has the value of: currentFunction.[[GetPrototypeOf]](). This value is know as the "superclass constructor".
- Referencing the superclass constructor, when its value is null, throws a TypeError expression.
- A new super or new super Arguments expression invokes the superclass constructor's [[Construct]] internal method passing as the receiver argument, the current value of new^.
- A super Arguments expression invokes the superclass constructor's [[Call]] internal method passing the caller's this value as the this parameter.
There is a Rationale that further explains some of these design changes.