Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[es6-super-construct] default constructor body for null extends #22

Closed
allenwb opened this issue Jan 9, 2015 · 4 comments
Closed

[es6-super-construct] default constructor body for null extends #22

allenwb opened this issue Jan 9, 2015 · 4 comments

Comments

@allenwb
Copy link
Member

allenwb commented Jan 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

@allenwb
Copy link
Member Author

allenwb commented Jan 9, 2015

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.

@wycats
Copy link
Contributor

wycats commented Jan 9, 2015

@allenwb Am I understanding correctly that an 'extends null' class would have |this| in its constructor initialized with a normal JavaScript object?

@allenwb
Copy link
Member Author

allenwb commented Jan 9, 2015

@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.

@domenic
Copy link
Member

domenic commented Mar 25, 2015

ES6 is done, doing some housecleaning!

@domenic domenic closed this as completed Mar 25, 2015
@zloirock zloirock mentioned this issue Apr 14, 2016
jmdyck pushed a commit to jmdyck/ecma262 that referenced this issue May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants