在反應本土例如: https://github.com/facebook/react-native如何理解這種語法? var {...} = React;
var React = require('react-native');
var { ScrollView, TouchableHighlight, Text } = React;
var TouchDemo = React.createClass({
render: function() {
return (
<ScrollView>
<TouchableHighlight onPress={() => console.log('pressed')}>
<Text>Proper Touch Handling</Text>
</TouchableHighlight>
</ScrollView>
);
},
});
這是什麼語法是什麼意思?
var { ScrollView, TouchableHighlight, Text } = React;
我在nodejs console中鍵入它導致語法錯誤。這種特殊的Javascript語法僅適用於React Native嗎?
感謝
我想這是一個ES6功能,但它可能是JSX特有的ng以及https://developer.mozilla。org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment –
查看解構賦值[here](https://www.airpair.com/javascript/posts/using-es6-harmony-with-nodejs#2 -2解構分配)和[這裏](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)。這是語法糖來保存輸入。 – jfriend00