ES6新特性
① 新增let和const:不存在变量提升
② 箭头函数:function aa = ()=>{} 形参只有一个可省略(),只有一个表达式可以直接return;箭头函数中的 this 始终指向箭头函数定义时离 this 最近的一个函数,如果没有最近的函数就指向 window。
③ 模板字符串: 我是 ${name}
④ 解构赋值:
let [a, b, c] = [1, 2, 3];let { foo, bar } = { foo: 'aaa', bar: 'bbb' }; // foo = 'aaa' // bar = 'bbb';set(),本身是构造函数
let set = new Set([1,2,2,1,4,3,5])
console.log(set)//Set(5) {1, 2, 4, 3, 5}
数组去重:Array.from(new Set( arr )) ; […new Set(arr)]
字符串去重:[…new Set(str) ]//str = “123415526” == 123456
⑤ 类:继承了父亲的属性改写了父亲的属性,不影响父亲的属性;
class father {
constructor(name, age) {
this.name = name;
this.age = age;
}
say() {
console.log(`${this.name}说他${this.age}`)
}
}
let son1 = new father("李哈哈", 27);
// 继承:
class son2 extends father {
constructor(name, age, height) {
super(name, age);
this.height = height
}
//对父亲方法进行改写
say() {
console.log(`${this.name}说他${this.age}===>${this.height}`)
}
}
console.log(son1.say);//李哈哈说他27 + undefined--->不清楚为啥会有
console.log(new son2("桂花", 28, 1.63).say());//桂花说他28===>1.63 + undefined--->不清楚为啥会有
⑥ 模块化
export default {
name: 'lili',
fun: function () {
console.log("找工作哇!");
}
}
//HTML页面引入--<script ***type="module"***></script>
import desc from './3.js'
console.log(desc);
⑦ 拓展运算符 …
let arr = [1,2,3];
arr.push(...[33,55])
arr.push([313,515])
console.log(arr);//[ 1, 2, 3, 33, 55, [ 313, 515 ] ]