dimanche 15 novembre 2020

How can I retrieve a class from a method reference in javascript?

I would like to do this:

function call(method) {
    const object = // Retrieve the class that declares the method and then construct an instance dynamically.
    method.call(object) // So 'this' is bound to the instance.
}

call(MyClass.prototype.myMethod)
call(AnOtherClass.prototype.anOtherMethod)

My goal is to create the instance from a dependency container. That's why the method has to be bound to an instance that will have all the dependencies required by the class.





Aucun commentaire:

Enregistrer un commentaire