I'd like to inherit some class MyClass
from some built-in class Class
in the conventional way, i.e. without the new "class" syntax. I'm used to the following:
MyClass.prototype = Object.create(Class.prototype);
function MyClass() {
Class.apply(this, arguments); // calling the superconstructor => "TypeError: Class constructor: 'new' is required"
...
}
var myObject = new MyClass(...);
As indicated, for many newer classes, usage of "new" with the constructor is enforced (e.g. for MediaSource
). But new
will be used with MyClass
and will already have created a new object, so that I should not create yet another object inside the constructor. What am I supposed to do, or what is the equivalent here of the super()
call in the new class
syntax?
The only way I could think of, is to indeed create an instance with new Class()
and explicitly return this instance from the constructor. But then the prototype of MyClass (which might have additional properties) is not really used ...