首先感謝阮老師的Es6教材的指導(dǎo)
鏈接
//數(shù)組的解構(gòu)賦值 對應(yīng)位置呛踊,對應(yīng)變量賦值
example(){
return [10,20,30];
}
var [a,b,c] = this.example();
//對象賦值
var {obj1,obj2} = {obj1:'firsr',obj2:'second'};
//遍歷Map結(jié)構(gòu)
var map = new Map();
map.set('first','hello');
map.set('second','world');
for (let [key,value] of map){
//console.warn(key+value);
}
//獲取鍵名
for (let [key] of map){
// ...
}
//獲取 鍵值
for (let [,value] of map){
// ...
}
//chartCodeAt(index) chartAt(index)
var codeS = '中a';
//console.warn(codeS.charCodeAt(0)+codeS.charAt(0)); //20013 中
//includes() 是否找到 startsWith() 是否在頭部 endsWith() 是否在尾部 默認從0開始砾淌,也可以指定搜索位置
var inclu = 'Please sitDown!';
// console.warn(inclu.startsWith('Ple'));//true
// console.warn(inclu.includes('ea'));//true
// console.warn(inclu.endsWith('!'));//true
// console.warn(inclu.includes('ea',3));//false //從下標為3的位置,到length 結(jié)束
// console.warn(inclu.startsWith('o',11));//true //從下標為3的位置谭网,到length 結(jié)束
// console.warn(inclu.endsWith('l',2));//true //【注意】這里是指起始位置到下標為2的地方結(jié)束
//repeat(n)返回一個新的字符串汪厨,表示將原字符串重復(fù)n次
console.warn('lee'.repeat(2));//leelee
//模版字符串 (`)來標識
//模版字符串 (`)來標識
//1.普通字符串的使用 `hello '\n' world!`
/*
* 2.多行字符串 可保留輸入格式
* `hello
* world`
*
*
*
* */
//3.字符串變量嵌入 {`What is the date? ${intro}` 【注意】需要將變量名寫在${}中
var intro = 'Today is monday!';
<Text>{`hello '\n'
world!`}</Text>
<Text>{`What is the date? ${intro}`}</Text>
屏幕快照 2017-05-17 下午3.26.07.png
最后附上完整代碼
import React, {Component} from 'react'
import {
Navigator,
View,
Text,
StyleSheet,
ScrollView
} from 'react-native'
export default class Es6 extends Component {
example(){
return [10,20,30];
}
render() {
//數(shù)組的解構(gòu)賦值 對應(yīng)位置,對應(yīng)變量賦值
var [a,b,c] = this.example();
var [foo,[[bar]],baz] = [0,[[1]],2];
//對象賦值
var {obj1,obj2} = {obj1:'firsr',obj2:'second'};
//遍歷Map結(jié)構(gòu)
var map = new Map();
map.set('first','hello');
map.set('second','world');
for (let [key,value] of map){
//console.warn(key+value);
}
//獲取鍵名
for (let [key] of map){
// ...
}
//獲取 鍵值
for (let [,value] of map){
// ...
}
var codeS = '中a';
//console.warn(codeS.charCodeAt(0)+codeS.charAt(0)); //20013 中
//includes() 是否找到 startsWith() 是否在頭部 endsWith() 是否在尾部 默認從0開始愉择,也可以指定搜索位置
var inclu = 'Please sitDown!';
// console.warn(inclu.startsWith('Ple'));//true
// console.warn(inclu.includes('ea'));//true
// console.warn(inclu.endsWith('!'));//true
// console.warn(inclu.includes('ea',3));//false //從下標為3的位置劫乱,到length 結(jié)束
// console.warn(inclu.startsWith('o',11));//true //從下標為3的位置,到length 結(jié)束
// console.warn(inclu.endsWith('l',2));//true //【注意】這里是指起始位置到下標為2的地方結(jié)束
//repeat(n)返回一個新的字符串锥涕,表示將原字符串重復(fù)n次
console.warn('lee'.repeat(2));//leelee
//模版字符串 (`)來標識
//1.普通字符串的使用 `hello '\n' world!`
/*
* 2.多行字符串 可保留輸入格式
* `hello
* world`
*
*
*
* */
//3.字符串變量嵌入 {`What is the date? ${intro}` 【注意】需要將變量名寫在${}中
var intro = 'Today is monday!';
return (
<ScrollView style={styles.container}>
<Text>{a}+衷戈+{c}= {a+b+c}</Text>
<Text>{foo}+{bar}+{baz}</Text>
<Text>{obj1}+{obj2}</Text>
<Text>{`hello '\n'
world!`}</Text>
<Text>{`What is the date? ${intro}`}</Text>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
paddingTop:30,
},
});