简体   繁体   English

这对本机初始化代码有何反应?

[英]What does this react native init code mean?

What does this code actually mean? 此代码实际上是什么意思?

var React = require('react-native');
var {
    AppRegistry,
    StyleSheet,
    Text,
    Image,
    View,
    } = React;

I know the React is a module imported by node, Does it copy the React object to the list above? 我知道React是由节点导入的模块,它将React对象复制到上面的列表中吗?

And I added the 我添加了

var {Image} = React;

it works too. 它也可以。 I'm new to Node.js and React and get confused. 我是Node.js和React的新手,感到困惑。

[SOLVED] by Ramanlfc: This is a destructing assignment : Ramanlfc的[已解决]:这是一个破坏性的任务

The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and object literals. 析构分配语法是一个JavaScript表达式,它可以使用与数组和对象文字相同的语法来从数组或对象中提取数据。

As mentioned by Ramanlfc in the comments; 正如Ramanlfc在评论中提到的那样 it is the ECMAScript 2015 Destructuring assignment syntax. 这是ECMAScript 2015 解构分配语法。

Essentially that statement 本质上说

var {
    AppRegistry,
    StyleSheet,
    Text,
    Image,
    View,
} = React;

is the equivalent of 等于

var AppRegistry = React.AppRegistry,
    StyleSheet = React.StyleSheet,
    Text = React.Text,
    Image = React.Image,
    View = React.View;

It's an easier way of assigning object properties to variables of the same name; 这是一种将对象属性分配给同名变量的简便方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM