jeudi 14 janvier 2016

ES6 creating new instance with reflection

I have a use case where I need to persist the name of a given class in a cookie so that I can create an instance of it later when the client returns. I would like to be able to do something like this:

class MyClass {
}

var a1 = new MyClass()
var className = a.class.name()//like in Java..
var a2 = Class.forName(className).newInstance();

Is this possible in ES6?





Aucun commentaire:

Enregistrer un commentaire