P粉5783439942023-08-25 10:55:29
This is destructuring assignment. It is a new feature of ECMAScript 2015.
var { AppRegistry, StyleSheet, Text, View, } = React;
Equivalent to:
var AppRegistry = React.AppRegistry; var StyleSheet = React.StyleSheet; var Text = React.Text; var View = React.View;
P粉3500367832023-08-25 10:49:56
It is called Destructuring assignment and is part of the ES2015 standard .
var o = {p: 42, q: true}; var {p, q} = o; console.log(p); // 42 console.log(q); // true // 分配新的变量名 var {p: foo, q: bar} = o; console.log(foo); // 42 console.log(bar); // true
var foo = ["one", "two", "three"]; // 不使用解构 var one = foo[0]; var two = foo[1]; var three = foo[2]; // 使用解构 var [one, two, three] = foo;