目录
一、对象
1、属性简写
eg:
var name = "mumu";
var obj={name};
2、动态属性
eg:var obj = {[a+b]:"小曾"}
3、函数简写
eg:{say(){}}
4、继承
eg:
Object.setPrototypeOf(child.parent)
super
二、类
特点:
1、用class声明 本质是function
2、constructor 构造
3、extends 继承
4、new 实例化
5、类名建议大写 开头
eg:
class Cat extends Animal{
constructor(name,color){
super(name);
this.color=color;
}
say(){}
}
var c1=new Cat("小猫咪","五彩斑斓的黑");
三、模块化
<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 合并默认
import * as utils from url
文件打开必须是http协议,不能是D: C:file 协议
四、Set 集合
1、内容不重复
2、初始化
eg:var s1=new Set ([1,2,1,2,3,4,5,3])
3、利用set特性去重
eg:arr=[...new Set(arr)]
4、常用方法(类似于数组)
add 添加
delete 删除
clear 清除
has 检查是否有
size 长度
五、weakSet 集合
1、内容不重复
2、内容必须是引用对象
eg:new WeakSet([,,,,,])
六、Map 图(类似对象)
1、特点
键可以是任意类型
2、初始化:
new Map([["zql",20],["mumu",30],[8,200]])
3、方法:
set 添加
get 获取
has 监测
size 长度
delete 删除
clear 清空
七、WeekMap
1、特点
key都是弱引用
八、可迭代对象
可以被for of 遍历
String 字符串
Array 数组
Set 集合
Map 图
keys() 键集合
values()值集合
enteries() 键与值的集合
for of
eg:for(let v of arr){
console.log(v);
}