最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to use Harmony (ES6) with JSXTransformer.js? - Stack Overflow

programmeradmin3浏览0评论

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

<script src=".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?

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?

Share Improve this question asked Sep 16, 2014 at 18:35 danvkdanvk 16.9k8 gold badges78 silver badges131 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 21

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>
发布评论

评论列表(0)

  1. 暂无评论