码迷,mamicode.com
首页 > 其他好文 > 详细

es6新特性

时间:2019-05-21 14:46:58      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:efi   const   on()   var   function   箭头   func   ber   window   

1.箭头函数

var foo = function(){return 1;};
//等价于
let foo = () => 1;

箭头函数中的 this 指的不是window,是对象本身。

function aa(){
  this.bb = 1;
  setTimeout(() => {
    this.bb++; //this指向aa
    console.log(this.bb);
  },500);
}

aa(); //2

2.class关键字

3.模板字符串

4.let与const 关键字

5.for of 值遍历

我们都知道for in循环用于遍历数组,类数组或对象,ES6中新引入的for of循环功能相似,不同的是每次循环它提供的不是序号而是值

var someArray = [ "a", "b", "c" ];
 
for (v of someArray) {
    console.log(v);//输出 a,b,c
}

6.Promise

7.解构

解构赋值是ES6中推出的一种高效、简洁的赋值方法

//通常情况下
var first = someArray[0];
var second = someArray[1];
var third = someArray[2];

//解构赋值
let [first, second, third] = someArray; //比上面简洁多了吧

//还有下面例子
let [,,third] = [1,2,3];
console.log(third); //3

let [first,...last] = [1,2,3];
console.log(last); //[2,3]

//对象解构
let {name,age} = {name: "lisi", age: "20"};
console.log(name); //lisi
console.log(age); //20

let {ept} = {};
console.log(ept); //undefined

8.新的API(Math,Number,String)

es6新特性

标签:efi   const   on()   var   function   箭头   func   ber   window   

原文地址:https://www.cnblogs.com/IT123/p/10899367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!