Skip to content

Dynamic loading of classes by name #10

@pcan

Description

@pcan

Implement dynamic class loading in classForName. We want to achieve something like this

let clazz = Reflection.classForName("folder1.folder2.sourceFile#module1.MyClass");
let ctor = clazz.getConstructor();
let obj = new ctor();

Note that folder1/folder2/sourceFile.js has not been loaded yet, so registerClass has not been executed yet for MyClass.

At the moment, we have to deal with:

  • node/commonjs: synchronous loading (we can leave the API as is)
  • AMD: if we want to support AMD, classForName has to return something like a promise, or take a callback function as argument.

We would not want to make two different APIs for the two systems. One possible solution may be an async function version of Reflection.classForName, but this will force us to drop support for targets before ES2015 (due to a TypeScript compiler rule).

Suggestions are welcome.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions