I used the following function to instantiate unknown classes for some time:
Kernel.prototype._construct = function (constr, args) { function F() { constr.apply(this, args);
If I use prototypes everything works:
function Person(name, surname) { this.name = name; this.surname = surname; } var person = Kernel._construct(Person, ["name", "surname"]);
However, some people use my library using native ES6 classes in node v4 +:
class Person { constructor(name, surname) { this.name = name; this.surname = surname; } } var person = Kernel._construct(Person, ["name", surname]);
They get the error:
TypeError: Class constructors cannot be invoked without 'new'
I need to be able to call a constructor with an unknown number of arguments. Any ideas on how to get around this?
source share