-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Super constructor return ignored #7710
Comments
The following can be used as a workaround: class Collection extends Array {
constructor(...args) {
super();
const first = arguments[0];
if (args.length === 1 && typeof first === 'number') {
super.push.call(this, first);
} else {
super.push.apply(this, args);
}
}
}
const a = new Collection(3, 2, 1);
const b = new Collection(3);
console.log(a, b); |
Actually, it doesn't - it's impossible to subclass builtin classes like If you transpile this with Babel, |
(Since it wasn't explicitly answered) The reason the compiler complains about the two So |
TypeScript Version:
nightly (1.9.0-dev.20160313)
Code
Expected behavior:
The
Array
is correctly subclassed and the instances are created correctly.Actual behavior:
The instances are not created correctly.
Notes:
IArrayConstructor
to get it to not squark.this
#7574.Questions:
The text was updated successfully, but these errors were encountered: