ES6笔记记录

ES6

允许给函数参数赋初始值

JavaScript运行机制

事件循环

同步与异步任务

  • 同步程序执行完成后,执行异步程序

单线程

  • js是单线程的,一个任务完成后才能执行另一个任务

process.nextTick与setImmediate方法

事件循环

宏任务与微任务

  • 宏任务:计时器、ajax、读取文件

  • 微任务:promise.then

  • 执行顺序

    • 同步任务
    • nextTick
    • 微任务
    • 宏任务
    • setImmediate

promise 对象

  • new Promise()
    
    let p = new  Promise((resolve)>={
    
    console.log(1);
    
    //resolve();
    
    
    p.then((data)>={
    console.log(data);
    //1
    })
    

async函数

async function fun(){

reture 1

}

fun().then((data)>={

console.log(data);

//1

})
let p1 = new Promise((resolve)>={

resolve(1)

})

let p2 = new Promise((resolve)>={

resolve(2)

})

async function fun(){

let a = await p1;    
//await 取出resolve里面的值

let b = await p2;

console.log(a);

console.log(b);

}

fun();

//1  2

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wDLfRQg5-1658153092071)(C:\Users\EBIZ\AppData\Roaming\Typora\typora-user-images\image-20210720100107310.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kVswnXnf-1658153092074)(C:\Users\EBIZ\AppData\Roaming\Typora\typora-user-images\image-20210720102745512.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KFbkIrbu-1658153092074)(C:\Users\EBIZ\AppData\Roaming\Typora\typora-user-images\image-20210720105339619.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LIIIh6f7-1658153092075)(C:\Users\EBIZ\AppData\Roaming\Typora\typora-user-images\image-20210720105924635.png)]

箭头函数不会改变它的this指向,在哪里定义函数,this指向哪里

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VTI7Qf1A-1658153092076)(C:\Users\EBIZ\AppData\Roaming\Typora\typora-user-images\image-20210720130301461.png)]

Promise对象

类与继承

原型对象实现继承

this的指向

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UPGJFIYr-1658153092078)(C:\Users\EBIZ\AppData\Roaming\Typora\typora-user-images\image-20210720145010755.png)]

call apply bind

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-K0DMoEo3-1658153092079)(C:\Users\EBIZ\AppData\Roaming\Typora\typora-user-images\image-20210720150033479.png)]

call 和apply 可以直接调用函数,只是传参的形式不一样,call是 罗列传参,而apply传参数是一个数组
而bind 不能直接调用函数,它是返回函数,bind的传参形式与call是一样的
call 的实际应用
  • call 可以实现多重继承

    +function Animal() {
    
      ​      // this指向cat
    
      ​      this.eat = function() {
    
      ​        console.log("吃东西");
    
      ​      }
    
      ​    }
    
      
    
      ​    function Bird() {
    
      ​      this.fly = function() {
    
      ​        console.log("我会飞");
    
      ​      }
    
      ​    }
    
      
    
      ​    function Cat() {
    
      ​      // 把Animal函数的this指向改了 这样就实现了方法的继承
    
      ​      Animal.call(this); //核心
    
      ​      Bird.call(this); //核心
    
      ​      // this指向cat
    
      ​    }
    
      ​    let cat = new Cat();
    
      ​    cat.eat();
    
      ​    cat.fly();
    
    
    

    ​ Bird.call(this); //核心

    ​ // this指向cat

    ​ }

    ​ let cat = new Cat();

    ​ cat.eat();

    ​ cat.fly();

    
    
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值