I am trying to create a function that takes a classname and parameters as arguments, and tries to define them inside a sandbox environment.
E.g., the function may be called with arguments name: "Dog", args: {name: "string", isGoodBoy: "boolean"}
. I then would like to define a class inside a sandbox named Dog that has 2 class variables, name: string and isGoodBoy: boolean.
I've tried to define the code with the vm module (see test example below), but to no avail - Node.js fails to execute the code given to the context.
vm.runInContext(
"export class eval(object.name) extends CoreObject {\n" +
" constructor() {\n" +
" console.log(\"I am here\");\n" +
" }\n" +
"}", context);