是否可以将Harmony(ES6)与JSXTransformer.js一起使用? [英] Is it possible to use Harmony (ES6) with JSXTransformer.js?
问题描述
我很幸运使用React的 JSXTransformer.js 来开发使用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>
为了减少样板,我想使用Harmony的一些功能,例如: 箭头功能。 Facebook的 JSX编译器服务有一个和声复选框,可以将ES6转换为更传统的JS:
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);
是否可以使用浏览器中的JSX启用此转换?
Is it possible to enable this transformation with the in-browser JSX?
推荐答案
此功能 。而不是 type =text / jsx
,而是设置 type =text / jsx; harmony = true
。例如:
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>
这篇关于是否可以将Harmony(ES6)与JSXTransformer.js一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!