Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up[es6-super-construct] default constructor body for null extends #22
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Jan 9, 2015
Member
Not really.
You also have to evaluated the function definition for the constructor at the same logical point in the program. So you can use the value of the extends clause to select which of two possible constructor function expression to evaluate. That's exactly what the ES6 spec currently describes.
Here is a possible "compilation" of class extends foo {}:
%extendsValue = foo;
%ctor = %extendsValue ===null ? function() {} : function( ){ your translation of "super(...Arguments)"};
%ctor.prototype.__proto__ = %extendsValue===null ? null : %extendsValue.prototyype;
If (%extendsValue!==null) %ctor.__proto__= %extendsValue;
//%ctor is the value of the function expression.Something I will have to look further at is to make sure that there aren't any early error dependencies upon the extends clause value.
|
Not really. You also have to evaluated the function definition for the constructor at the same logical point in the program. So you can use the value of the extends clause to select which of two possible constructor function expression to evaluate. That's exactly what the ES6 spec currently describes. Here is a possible "compilation" of %extendsValue = foo;
%ctor = %extendsValue ===null ? function() {} : function( ){ your translation of "super(...Arguments)"};
%ctor.prototype.__proto__ = %extendsValue===null ? null : %extendsValue.prototyype;
If (%extendsValue!==null) %ctor.__proto__= %extendsValue;
//%ctor is the value of the function expression.Something I will have to look further at is to make sure that there aren't any early error dependencies upon the extends clause value. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wycats
Jan 9, 2015
Contributor
@allenwb Am I understanding correctly that an 'extends null' class would have |this| in its constructor initialized with a normal JavaScript object?
|
@allenwb Am I understanding correctly that an 'extends null' class would have |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Jan 9, 2015
Member
@wycats That's right.
class extends null {} is a way to say class {} but with the restriction that the class's prototype object does not inherit from Object.prototype.
|
@wycats That's right.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
ES6 is done, doing some housecleaning! |
allenwb commentedJan 9, 2015
On Jan 9, 2015, at 7:43 AM, Erik Arvidsson wrote:
Happy New Year!
(I don't know which thread is the active thread.)
https://github.com/tc39/ecma262/blob/master/workingdocs/ES6-super-construct%3Dproposal.md
Point 12: If a class definition does not include an explicit constructor definition, it defaults to: constructor(...args) {super(...args)}; if the class has a non-null extends clause. Otherwise it defaults to: constructor() {};.
This is problematic since we have to evaluate the extends expression to know if it is null or not. This means that the default constructor needs to be:
constructor(...args) {
if (%extendsValue !== null) super(...args);
}
where %extendsValue is the result of evaluating the extends expression and it has to be captured for later references.
erik