Closed
Description
TypeScript Version: 1.8 and nightly (2.1.0-dev.20160805)
Code
class A {}
class B extends A {
private foo = 1;
}
Expected behavior:
// compiles into...
class A {}
class B extends A {
constructor() {
super(...arguments);
this.foo = 1;
}
}
Actual behavior:
// compiles into...
class A {}
class B extends A {
constructor(...args) {
super(...args);
this.foo = 1;
}
}
If you take the first compilation and feed it into Babel (loose mode), you will get (more or less)...
var A = function A() {
};
var B = function (_A) {
_inherits(B, _A);
function B() {
_A.apply(this, arguments);
this.foo = 1;
}
return B;
}(A);
But if you take the second version, you will get...
var A = function A() {
};
var B = function (_A) {
_inherits(B, _A);
function B() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_A.call.apply(_A, [this].concat(args));
this.foo = 1;
}
return B;
}(A);
Which is much less efficient – it allocates two extra arrays, reify arguments
into an array, extra concat
and ....call.apply
(o_0).