What I tried (which works in chrome)
var class_str = "class Test {};";
var a = eval(class_str);
console.log(new a());
Raises following error in Firefox 46:
TypeError: a is not a constructor
a is undefined and using new A() returns ReferenceError: A is not defined.
What is different on Firefox?
var class_str = "class Test {}; return Test;";SyntaxError: return not in function@DanielA.White Chrome does not work that way, too.class Test {};into the console, you'll see that Firefox gives youundefined, while Chrome gives you the class. So Chrome is providing a value for the last statement in the program, while Firefox isn't. Not sure which is correct. Another example of a statement returning a value would be to see the result of aforstatement usingeval.var x = eval("for (var i = 0; i < 10; i++) { i }"); console.log(x); // 9(class Test {})