Is it possible to use Harmony (ES6) with JSXTransformer.js?

旧时模样 提交于 2019-12-23 07:52:56

问题


I've had great luck using React's JSXTransformer.js to develop using JSX in the browser:

<script src="http://fb.me/JSXTransformer-0.11.1.js"></script>
<script type="text/jsx">
/** @jsx React.DOM */
...
</script>

To reduce boilerplate, I'd like to use some of the features from Harmony, e.g. arrow functions. Facebook's JSX Compiler Service has a harmony checkbox which transforms ES6 to more traditional JS:

var f = v => this.props[v];
// becomes var f = function(v) { return this.props[v]; }.bind(this);

Is it possible to enable this transformation with the in-browser JSX?


回答1:


This feature was added in React v0.11. Instead of type="text/jsx", you set type="text/jsx;harmony=true". For example:

<script type="text/jsx;harmony=true">
/** @jsx React.DOM */
var f = v => v*v;
console.log(f(2));  // logs 4
</script>


来源:https://stackoverflow.com/questions/25876088/is-it-possible-to-use-harmony-es6-with-jsxtransformer-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!