jeudi 3 septembre 2015

Constructing an ES6 class by name (from a string) [duplicate]

This question already has an answer here:

I'm using ES6 classes and would like to be able to construct instances 'dynamically' based on strings. Here's a quick example:

class Foo { }
class Bar { }

const className = 'Foo';
const classInstance = createInstance(className); 

... where createInstance constructs the class indicated by the supplied string.

Any ideas?





Aucun commentaire:

Enregistrer un commentaire