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)
发表回复