为什么可以在 React Native 中使用解构赋值? [英] why it possible to use destructuring assignment in React Native?

查看:48
本文介绍了为什么可以在 React Native 中使用解构赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

react native教程的例子中,我发现ECMAScript 2015 (ES6) 标准中定义的语法称为解构赋值.但据我所知,iojs 和 nodejs 不支持这种语法.我如何在 React Native 中使用它?

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?

推荐答案

你说得对,nodejs 和 iojs 不支持 ES6 语法.但反应原生:

You are right nodejs and iojs do not support ES6 syntax. But react native:

从 0.5.0 版本开始,React Native 附带 Babel JavaScript 编译器.

As of version 0.5.0, React Native ships with the Babel JavaScript compiler.

在这里阅读更多

这意味着在 React 打包器中有另一个转译器(Babel)在工作.它从 ECMAScript 2015 (ES6) 转换为 ES5.这允许您使用 ES6 功能,例如:解构、计算属性键、类、箭头函数、块范围变量等.

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.

如果您想在 React(而非 Native)应用中使用这些功能,您需要在项目中包含 Babel.

If you want to use those features in the React (not Native) app, you will need to include Babel in your project.

没有其他转译器.

React 和 React Native 都切换了各自的构建系统以使用 Babel.这取代了 JSTransform,这是我们在 Facebook 编写的源转换工具.

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.

更多在 弃用 JSTransform和反应工具

这篇关于为什么可以在 React Native 中使用解构赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆