var {
StyleSheet,Text,View
} = React;
var StyleSheet = React.StyleSheet; var Text = React.Text; var View = React.View
var a = 1; var b = 2; var c = 3;
var [a, b, c] = [1, 2, 3];
var array = [1, 2, 3];
//传统写法
array.forEach(function(v, i, a) {
console.log(v);
});
//ES6
array.forEach(v => console.log(v));
var sum = (num1, num2) => { return num1 + num2; }
//等同于:
var sum = function(num1, num2) {
return num1 + num2;
};
var people=['Wayou','John','Sherlock'];
//sayHello函数本来接收三个单独的参数人妖,人二和人三
function sayHello(people1,people2,people3){
console.log(`Hello ${people1},${people2},${people3}`);
}
//但是我们将一个数组以拓展参数的形式传递,它能很好地映射到每个单独的参数
sayHello(...people);//输出:Hello Wayou,John,Sherlock
//而在以前,如果需要传递数组当参数,我们需要使用函数的apply方法
sayHello.apply(null,people);//输出:Hello Wayou,John,Sherlock
var props = {};
props.foo = x;
props.bar = y;
var component = <Component {...props} />;
//等价于
var props = {};
props.foo = x;
props.bar = y;
var component = <Component foo={x} bar={y} />;
它也可以和普通的XML属性混合使用,需要同名属性,后者将覆盖前者:
JavaScript
var props = { foo: 'default' };
var component = <Component {...props} foo={'override'} />;
console.log(component.props.foo); // 'override'
class PropertyView extends Component {
render() {
return (
<View></View>
)
}
}
//等价于
var PropertyView = React.createClass({
render() {
return (
<View></View>
)
}
})
React.createClass({
render() {
return (
<View></View>
)
}
})
//等价于
React.createClass({
render : function() {
return (
<View></View>
)
}
})
var {
StyleSheet,
Text,
View
} = React;
var StyleSheet = React.StyleSheet; var Text = React.Text; var View = React.View
var a = ; var b = ; var c = ;
var [a, b, c] = [, , ];
var array = [, , ];
//传统写法
array.forEach(function(v, i, a) {
console.log(v);
});
//ES
array.forEach(v => console.log(v));
var sum = (num, num) => { return num + num; }
//等同于:
var sum = function(num, num) {
return num + num;
};
var people=['Wayou','John','Sherlock'];
//sayHello函数本来接收三个单独的参数人妖,人二和人三
function sayHello(people,people,people){
console.log(Hello ${people},${people},${people});
}
//但是我们将一个数组以拓展参数的形式传递,它能很好地映射到每个单独的参数
sayHello(...people);
//输出:Hello Wayou,John,Sherlock
//而在以前,如果需要传递数组当参数,我们需要使用函数的apply方法
sayHello.apply(null,people);
//输出:Hello Wayou,John,Sherlock
而在React中,延展操作符一般用于属性的批量赋值上。在JSX中,可以使用…运算符,表示将一个对象的键值对与ReactElement的props属性合并。
var props = {};
props.foo = x;
props.bar = y;
var component = <Component {...props} />;
//等价于
var props = {};
props.foo = x;
props.bar = y;
var component = <Component foo={x} bar={y} />;
var props = { foo: 'default' };
var component = <Component {...props} foo={'override'} />;
console.log(component.props.foo);
// 'override'
class PropertyView extends Component {
render() {
return (
<View></View>
)
}
}
//等价于
var PropertyView = React.createClass({
render() {
return (
<View></View>
)
}
})
React.createClass({
render() {
return (
<View></View>
)
}
})
//等价于
React.createClass({
render : function() {
return (
<View></View>
)
}
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有