ES6初学填坑

一、简介
ECMAScript 和 JavaScript 的关系是,前者是后者的规格,后者是前者的一种实现。日常场合,这两个词是可以互换的。(浏览器脚本语言)
babel转码器:使不支持es6的环境下的语法转义为es5语法
二、重点
1.let和const

2.变量解构赋值

//数组式,对象式,字符串式,数值,函数参数!!,
let [a, b, c] = [1, 2, 3]; //从数组中提取,对应赋值。(模式想匹配即可)
let [bar, foo] = [1]; //不匹配,underfind
//用途
//交换变量,返回多个值,输入模块的指定方法!!

3.模板字符串

4.箭头函数

5.扩展运算符
将一个数组转为用逗号分隔的参数序列(spread)

console.log(...[1, 2, 3]) //1,2,3

6.Proxy(代理)
元编程:对编程语言进行编程(配置?)
概念:外界访问—>拦截(接收)—>过滤和改写—>代理某些操作
原理:构造函数,get与set

7.Promise对象
异步编程解决方案,传统的解决方案:回调函数和事件。

const promise = new Promise(function(resolve, reject) {
  if (/* 异步操作成功 */){
    resolve(value);
  } else {
    reject(error);
  }
});
promise.then(function(value) {
  // success
}, function(error) {
  // failure
}).catch(function(error) {
  // 处理 getJSON 和 前一个回调函数运行时发生的错误
  console.log('发生错误!', error);
}).finally();

8.async 函数
Generator 函数的语法糖

const asyncReadFile = async function () {
  const f1 = await readFile('/etc/fstab');
  const f2 = await readFile('/etc/shells');
  console.log(f1.toString());
  console.log(f2.toString());
};

9.Class语法
对象原型的语法糖

//定义类
class Point {
  constructor(x, y) { //构造函数
    this.x = x;
    this.y = y;
  }

  toString() {
    return '(' + this.x + ', ' + this.y + ')';
  }
}
//等同于
function Point(x, y) { //构造函数
  this.x = x;
  this.y = y;
}

Point.prototype.toString = function () { //原型扩展
  return '(' + this.x + ', ' + this.y + ')';
};

继承:extends关键字,es5为原型链

class ColorPoint extends Point {
  constructor(x, y, color) {
    super(x, y); // 调用父类的constructor(x, y)
    this.color = color;
  }

  toString() {
    return this.color + ' ' + super.toString(); // 调用父类的toString()
  }
}

10.Module语法
模块:es5: CommonJS 和 AMD(Asynchronous Module Definition,异步模块加载机制)规范,服务器和浏览器
export输出,import输入

11.块级作用域,eslint

三、忽略
1.正则,函数,对象,数组,数值,字符串等的扩展(扩展了一些属性方法之类的)。
2.数据类型Symbol,表示独一无二的值。
3.新的数据结构 Set,类似数组,但成员的值都是唯一的,本身是一个构造函数。
4.新的Map 数据结构,类似对象,但键可以不是字符串。
5.Reflect对象,Generator 函数,Iterator 和 for…of 循环,修饰器(Decorator)函数。
6.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值