I want to invoke functions of a class by their names inside a string. I know my best option are Mirrors.
var ref = reflect(new TestClass());
ref.invoke(Symbol("test"), []);
It works fine, I can call the function test by a string. But I also want to put "TestClass" inside a string. Is it possible somehow ?
var ref = reflect("TestClass");
ref.invoke(Symbol("test"), []);
Jonas
You can do something like this:
Note, that this implementation does require that
myMethodis static since we are never creating any object but only operate directly on the class itself. You can create new objects from the class by callingnewInstanceon theClassMirrorbut you will then need to call the constructor.But I hope this is enough. If not, please ask and I can try add some more examples.