If you want it to work with JSX, you can transpile the code with something like Babel before you execute it.
For example, when using the browser version of Babel:
var jsCode = babel.transform(jsxCode);
eval(jsCode.code);
There's also a run
method you can use to simply execute the code:
babel.run(code);
Both transform
and run
take an optional options
hash; check the documentation for more details.
Of course, as is standard, be careful with eval
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…