关于javascript:ES6必知速看2

4次阅读

共计 1372 个字符,预计需要花费 4 分钟才能阅读完成。

part 1 类

特点:用 class 申明,实质是 function,类名倡议大写结尾
为了更好的学习类,首先要把握以下单词:

constructor 结构器
super 超级
extends 继承                       
new 实例化                               

实例:

class Cat extends Animal{constructor(name,color){super(name);
    this.color = color;
    }
say(){}
}
var c1 = new Cat("小猫咪","五彩斑斓的黑")

part 2 模块化

script 标签的 type 类型更改为 module

<script type="module">

1. 导出

导出一个

export {name}

导出多个

export {name,fun}

导出默认

export default Cat

2. 导入

import {name} from url
import {name,fun} from url

导入默认

import Cat from url

合并默认

import Cat,{name,fun} from url

导入所有 as 关键字

import * as utils from url

文件关上必须是 http 协定,不能是 D:C: file 协定

prat 3 可迭代对象

能够被 for of 遍历

1.set 汇合

set 汇合特点就是不反复
初始化

var s1 = new Set([1,1,2])

数组去重

var arr = Array.from(s);

利用 set 个性去重

arr = [... new Set(arr)]

罕用办法:

add 增加
delete 删除
clear 清空
has 查看是否有
size 长度

2.Map 图

相似对象
特点:键能够是任意类型
初始化:

new Map([["zql",20], ["mumu",30], [8,200]])

办法

set 增加
get 获取
has 检测
size 长度
delete 删除
clear 清空

3. for of 遍历

keys() 键汇合
values() 值汇合
enteries() 键与值汇合

实例

for(let v of arr){console.log(v);
}

还有 String 字符串,Array 数组

part 4 promise

promise 承诺
reslove 实现解决
reject  回绝兑现

作用:
1. 延期工作解决方案(promise| 回调函数)
2. 异步操作同步执行(程序执行)

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/lo…
天气 http://wis.qq.com/weather/com…|forecast_24h|air&source=pc&province=${data.province}&city=${data.city}

getLocation()
.then(getWeather)
正文完
 0