ES6

1. var let const

let,const具有块级作用域,不具有变量提升

const 用于不能被重新赋值的变量

2. 箭头函数

我们经常要给回调函数给一个父级的this

常用办法就是 var self = this 定义一个变量接住他

使用 箭头函数,this 将不会受到影响,可以直接用this调用父级的this

3. 字符串

includes:

const string = 'food';

const substring = 'foo';

console.log(string.includes(substring));

返回的是布尔值。

string.repeat(str,count)

如果 string.length < count 即插入str到count == string.length为止

4. 模板字符串

const name = 'Tiger';

const age = 13;

console.log(`My cat is named ${name} and is ${age} years old.`);

5.解构

结构数组:

let [a, b, c, d] = [1, 2, 3, 4];

console.log(a);

console.log(b);

结构对象:

var luke = { occupation: 'jedi', father: 'anakin' };

var occupation = luke.occupation;

var father = luke.father;

-------------------------------------------------------------

let luke = { occupation: 'jedi', father: 'anakin' };

let {occupation, father} = luke;

console.log(occupation);

console.log(father);

6.模块

暴露对象:

function sumThree(a, b, c) {

return a + b + c;

}

export { sumThree };

引入:

import { sumThree } from 'math/addition';

7.参数

es6支持设置默认值:

function addTwoNumbers(x=0, y=0) {

return x + y;

}

8.rest参数

处理不定数目参数:

function logArguments(...args) {

for (let arg of args) {

console.log(arg);

}

}

9.展开操作

可以展示数组:

Math.max(...[-1, 100, 9001, -32]);

let cities = ['San Francisco', 'Los Angeles'];

let places = ['Miami', ...cities, 'Chicago']; // ['Miami', 'San Francisco', 'Los Angeles', 'Chicago']

10.类

创造类:

class Person {

constructor(name, age, gender) {

this.name  = name;

this.age    = age;

this.gender = gender;

}

incrementAge() {

this.age += 1;

}

}

11.Maps

可以理解成键值对

let map = new Map();

map.set('name', 'david');

map.get('name');

map.has('name');

12.Promises

远离回调地狱,可以转换成垂直代码

func1(value1)

.then(func2)

.then(func3)

.then(func4)

.then(func5, value5 => {

});

13.Generators

用同步的代码风格来写异步代码

function* genFunc() {

// (A)

console.log('First');

yield; //(B)

console.log('Second'); //(C)

}

ES7

1. includes

代码:

let array = ['1','2','3']

if(array.includes('2')){

console.log('有')

}

2. 指数操作符

2**3 == 8

ES8

1. object.entries()

代码:

let obj = {a: 1, b: 2, c: 3};

Object.entries(obj).forEach(([key, value]) =>{

console.log(key + ": " + value); // 输出a: 1, b: 2, c: 3

})

2.Async Await

异步看起来和同步写法一样

代码:

async fetchData(query) =>{

try {

const response = await axios.get(`/q?query=${query}`);

const data = response.data;

return data;

}

catch (error) {

console.log(error)

}

}

fetchData(query).then(data => {

this.props.processfetchedData(data)

})

原文链接:https://www.jianshu.com/p/f8145c799456

最新文章

  1. Employment Planning[HDU1158]
  2. 【php】使用gdb调试php程序
  3. Java for LeetCode 028 Implement strStr()
  4. alpha预乘
  5. WPF 详解模板
  6. Uva 10129 - Play on Words 单词接龙 欧拉道路应用
  7. malloc用法
  8. 关于JAVA Project.waitfor()死锁问题
  9. swift的struct本节描述结构的类型
  10. 关于Activity生命周期的总结
  11. 等到花儿也谢了的await
  12. 关于Mongodb的全面总结
  13. Mininet 系列实验(六)
  14. 利用ichart绘制网页图表
  15. [Django学习]静态文件处理
  16. 树莓派3B+学习笔记:13、不间断会话服务screen
  17. 1028: [JSOI2007]麻将
  18. Linux下重要日志及查看方式
  19. Yii2 的快速配置 api 服务 yii2-fast-api
  20. kernel对NTP的API,系统调用函数

热门文章

  1. Centos7下常见命令
  2. [LC] 246. Strobogrammatic Number
  3. MIAME|Highwire press
  4. motionbuilder卸载/完美解决安装失败/如何彻底卸载清除干净motionbuilder各种残留注册表和文件的方法
  5. python3下应用pymysql(第二卷)
  6. Esp8266和HomeKit
  7. Python-删除多级目录
  8. 吴裕雄--python学习笔记:sqlite3 模块
  9. js事件节流
  10. zookeeper伪分布式集群搭建