ES6简单复习记录

ES6

函数的扩展

  • 箭头函数
  • 数组的扩展运算符

对象的扩展

  • Object.keys、values、entries
  • 对象方法简写,计算属性(主要掌握)
  • 展开运算符(不是es6标准,但是babel也支持)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const key = 'myjob'
const obj = {
num: 1,
age: 18,
name: 'tiger',
job: function () {

},
work(){
console.log('hello')
},
key: 'fe', // 这样写打印出来,只是key: "fe"
[key]: 'fe', //
[key+'word']: 'fe'
}

打印的结果

image-20181010180702406

解构赋值

  • 数组解构
1
2
3
let arr = [1, 2]
let [num1, num2] = arr
console.log(num1,num2) // num1 = 1 num2 = 2
  • 对象解构
1
2
3
const obj = {type: 'IT',name: 'tiger'}
const {type, name} = obj
console.log(type,name) // type = IT name = tiger

模块化

告别seajs和require.js

  • Import,import{}
  • Export, Export default
  • Node现在还不支持,需要用require来加载文件

Async await(ES7)

更优雅的处理异步