ES6:
1.變量
var——重復定義不報錯;沒有塊級作用域;不能限制修改
let? 變量,不能重復定義,有塊級作用域
const 常量,不能重復定義,有塊級作用域
2.函數+參數
箭頭函數——簡寫:
1.只有一個參數,()可以省
2.只有一個語句,還是return,{}可以省
參數擴展——剩余參數
展開數組
3.數組
map? ? ? 映射? ? ? [31, 56, 89, 67]? =>? [不及格, 不及格, 及格, 及格]
reduce? ? 匯總? ? ? [..., ..., ...] => xx
filter? ? 過濾? ? ? [x, x, x, x, x, x] => [x, x, x...]
forEach? 迭代、遍歷
4.字符串
字符串模板? ? "xxx"? 'xxx'? `x${變量}xx`
5.面向對象
class
super
extends
6.promise? ? ? 解決異步
同步——只有操作完事了,才往下執行? ? ? ? ? ? ? 一次只能做一個事兒
異步——這個操作進行中,其他操作也能開始? ? ? ? 一次可以做多個事兒
異步的優勢:
1.用戶體驗好
2.高效
同步的優勢:
簡單
異步:
$.ajax({
url: '/get_banners',
type: 'post',
dataType: 'json',
success(){
$.ajax({
url: '/get_hot',
type: 'post',
dataType: 'json',
success(){
$.ajax({
url: '/get_list',
type: 'post',
dataType: 'json',
success(){
$.ajax({
url: '/get_hot',
type: 'post',
dataType: 'json',
success(){
},
error(){
alert('讀取失敗');
}
})
},
error(){
alert('讀取失敗');
}
})
},
error(){
alert('讀取失敗');
}
})
},
error(){
alert('讀取失敗');
}
})
同步:
let banners=$.ajax('/get_banners');
let hot=$.ajax('/get_hot');
let list=$.ajax('/get_list');
let hot=$.ajax('/get_hot');
//創建Promise對象
let p=new Promise(function (resolve, reject){
異步代碼...
});
//使用Promise對象
p.then(()=>{}, ()=>{});
7.generator
8.json
不兼容——高級瀏覽器,靠編譯解決