How should I extend the ES6 EventTarget constructor?
The following ES6 code is valid - I think.
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @language_out ES5
// ==/ClosureCompiler==
class MyEventTarget extends EventTarget {
constructor(mySecret) {
super();
this._secret = mySecret;
}
get secret() { return this._secret; }
};
but fails to compile cleanly in advanced mode to ES5, giving the warnings:
JSC_TYPE_MISMATCH: actual parameter 2 of $jscomp.inherits does not match formal parameter
found : function(this:EventTarget): ?
required: Function at line 1 character 28
class MyEventTarget extends EventTarget {
^
JSC_CONFLICTING_EXTENDED_TYPE: cannot extend this type; constructors can only extend constructors at line 2 character 2
constructor(mySecret) {
^
When using SIMPLE_OPTIMISATIONS it produces code, but when that code is run in the browser it errors with:
b = new MyEventTarget()
Uncaught TypeError: Failed to construct 'EventTarget': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
at new MyEventTarget (<anonymous>:52:23)
at <anonymous>:1:5
Am I doing something wrong?
Regards
Jan