ES7
- 沒(méi)有this
- 箭頭函數(shù)
對(duì)比
ES6
class Human{
this.gender = ‘male’
printGender(){
console.log(this.gender);
}
}
class Person extends Human{
constructor(){
super();
this.name='max'
this.gender = 'female'
}
printMyName(){
console.log(this.name);
}
}
ES7
class Human{
gender = ‘male’
printGender=()=>console.log(this.gender);
}
class Person extends Human{
name='max'
gender = 'female'
printMyName=()=> console.log(this.name);
}
Spread & Rest Operator
spread ...
split up arr or obj properties
const newArr = [...oldArr,1,2]
const newObj = {...oldObj,newP:5}
rest ...
merge a list of dunction arguments into an arr
function sortArr(...arg){
return args.sort()
}
const filter = (...args)=>return args.filter(e=>e===1);
Destructuring
Array destructuring
const n=[1,2,3]
[n1,,n3]=n;//=>n1=1,n3=3
Object destructuring
ob={name:'a',age:22}
{name}=ob
Reference & primitive types refresher 淺拷貝
參考ES6
Reference function
function 不是淺拷貝
object和arr是淺拷貝
import arr functions
1.map()
2.filter()
3.reduce()
4.find()
5.findIndex()
6.concat() 銜接
7.slice() 拆分
8.splice() 插入