ES6——语法

1. 到菜鸟教程看查看所有

 

2. asyn和await

  asyn:强制让内部的代码同步指向。在需要同步指向的代码await即可!

 

3. 合并数组

  [...前数组,...后数组] ,返回一个新数组

  使用

          let arr = [1,2,3];
                let arr2 = ['a','b','c'];
                console.log([...arr,...arr2]);

 

4. this指向

  this指向调用方法的对象

 

  弄清楚this指向,要懂js生成自定义对象

    自定义对象:

      js使用function定义自定义对象构造方法。而且只有成员变量。

      js使用让类型prototype指向函数附加自定义方法

function User(username , password){
    this.username = username;
    this.password = password;
}

let user = new User("cw","123123abc")
User.prototype.showInfo =  () => {
    console.log("userName: "+this.username+" password: "+this.password);
}
user.showInfo()

    this指向调用方法的对象

    可见,构造方法使用this为对象赋值。

 

    不想this指向调用方法的对象。使用() => {} 箭头函数。让this指向上一个调用方法的对象。

    {} 中的this同样指向上一个调用方法的对象

    

  

  

posted @ 2021-12-04 16:33  remix_alone  阅读(73)  评论(0)    收藏  举报