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

Comments

Projects
None yet
3 participants
@allenwb
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

This comment has been minimized.

Show comment
Hide comment
@allenwb

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@wycats

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?

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

This comment has been minimized.

Show comment
Hide comment
@allenwb

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@domenic

domenic Mar 25, 2015

Member

ES6 is done, doing some housecleaning!

Member

domenic commented Mar 25, 2015

ES6 is done, doing some housecleaning!

@domenic domenic closed this Mar 25, 2015

@zloirock zloirock referenced this issue Apr 14, 2016

Closed

extends null #543

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment