Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
How to "conventionally" (without class syntax) call a superconstructor in javascript that enforces the use of "new"?

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 ...

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!