Open stuartZhang opened 8 years ago
I suspect that the below statement throws an error that the "new" operator is required.
$traceurRuntime.superConstructor(B).apply(this, arguments);
In the ES6 program, the above corresponds to the statement "super();".
Referencing the feedback from the previus issue: https://github.com/google/traceur-compiler/issues/1413, it works as design.
There is a work around:
Compile:
class M extends Map {
constructor() {
super();
}
}
to:
class M extends Map {
constructor() {
const self = new Map();
self.__proto__ = M.prototype; // should really be new.targe.prototype
return self;
}
}
but there are 2 issues making this hard:
new.target
to work correctly and new.target
is too expensive to emulatenew.target.prototype
-> Object.getPrototypeOf(this)
You cannot touch this
before calling super()
in a constructor... but the compiled code is not using a constructor so it seems like it would work.
Another problem would be sub classing M
... The way we compile constructors doesn't do the right thing when an object is returned.
but the compiled code is not using a constructor so it seems like it would work.
Sure, it's approach for a compiled code, I use it for a long time.
Another problem would be sub classing
M
Here required complete subclassing reform like in babel@6
.
Bug: can't extend the native Map/WeakMap/Set/WeakSet class. Description: Only the ES 6 classes can't be extended. However, both the traditional built-in classes (e.g. Date) and the custom classes are able to be successfully extended to instantiate a sub class.
Source code:
Run the JavaScript file by:
Runtime Error: