问题
In the example of react native tutorial, I find syntax which is defined in ECMAScript 2015 (ES6) standard called Destructuring assignment. But as I know, iojs and nodejs do not support this syntax. How can I use it in React Native?
回答1:
You are right nodejs and iojs do not support ES6 syntax. But react native:
As of version 0.5.0, React Native ships with the Babel JavaScript compiler.
Read more here
That means that there is another transpiler (Babel) at work in the React packager. It converts from ECMAScript 2015 (ES6) to ES5. This allows you to use the ES6 features like: destructuring, computed property keys, classes, arrow functions, block-scoped variables and more.
If you want to use those features in the React (not Native) app, you will need to include Babel in your project.
Edit:
There is no another transpiler.
React and React Native have both switched their respective build systems to make use of Babel. This replaced JSTransform, the source transformation tool that we wrote at Facebook.
More in Deprecating JSTransform and react-tools
来源:https://stackoverflow.com/questions/31900951/why-it-possible-to-use-destructuring-assignment-in-react-native