ES6
變量聲明
let
0. let聲明和 var 聲明變量差不多
1. 在一對大{} 里面起作用
2. 不能重復聲明
3. 不會變量提升
什么是變量提升:用var 聲明變量 ,變量的使用在變量聲明前 默認值是undefined
const
0. const 和var 差不多
1. 通常用來聲明常量的 建議大寫
2. 聲明必須賦值
3. 聲明后不能修改*(復雜數(shù)據(jù)可以修改 數(shù)組)
數(shù)組解構(gòu)
1. 交換變量
2. 剩余值
3. 跳過
4. 默認值
對象解構(gòu)
01 對象簡寫
02 對象解構(gòu)
03 動態(tài)屬性
字符串模板
字符串模板 能讓再變量和字符串混合在一起書寫
01 所有的模板 ``
02 遇到變量用 ${變量? 值}
03 repeat(n)重復幾次n就是幾
數(shù)組高階方法
1. 遍歷數(shù)組 forEach
2. 映射數(shù)組 map
通過現(xiàn)有的數(shù)據(jù)反射出來新的數(shù)據(jù) 一一對應(yīng)
3. 過濾 filter
現(xiàn)有數(shù)組通過一定的規(guī)則過濾出新的數(shù)組
返回true 保留? false 不保留
箭頭函數(shù)
箭頭函數(shù)是函數(shù)的簡寫方式
01 基本寫法?
=> 前面是函數(shù)參數(shù)? =>后面是返回值也是執(zhí)行語句
省略function 關(guān)鍵字 return 關(guān)鍵字
02 多個參數(shù) 或者沒有 都用括號包起來
03 執(zhí)行語句有多個的時候 用{}包括起來
04 箭頭函數(shù)this 指的是函數(shù)上一層的this
函數(shù)
? 01. 默認參數(shù)
02. 不定參 參數(shù)不確定
function add(...arg){
...
? ? }
03. 拓展參數(shù) 把數(shù)組展開當參數(shù)
metting(...arr1)
04 最大值 max(...arg)
類
constructor 構(gòu)造器
super 超級
extends 繼承
set
不重復數(shù)組
new Set(arr2);
數(shù)組去重
ar arr = Array.from(s);
for of
遍歷
keys()鍵集合
values() 值得集合
entries ()鍵和值得集合
promise
promise 承諾
reslove 完成解決
reject? 拒絕兌現(xiàn)
作用:1. 延期任務(wù)解決方案(promise|回調(diào)函數(shù))
? ? ? ? ? ? 2.? 異步操作同步執(zhí)行(順序執(zhí)行)?
var p = new Promise(function(reslove,reject){}? ? ?
p.then(function(){},function(){})
// 2s 后對控制臺說 其實我觀察你
? // 3s 后對控制臺說 很久了
? // 5s 后對控制臺說? 我很中意你啊
function say1(){
? ? ? return new Promise(function(reslove,reject){
? ? ? ? ? setTimeout(function(){
? ? ? ? ? ? ? console.log("其實我觀察你");
? ? ? ? ? ? ? reslove();
? ? ? ? ? },2000)
? ? ? })
? }
say1()
? .then(say2)
? .then(say3);
1. 獲取當前的地址
2. 獲取當前的天氣(用到地址)
地址https://apis.map.qq.com/ws/location/v1/ip?key=3BFBZ-ZKD3X-LW54A-ZT76D-E7AHO-4RBD5&output=jsonp
天氣? http://wis.qq.com/weather/common?weather_type=observe|forecast_24h|air&source=pc&province=${data.province}&city=${data.city}`
getLocation()
? .then(getWeather)
網(wǎng)站上傳