ES6 basis of --Class class

In the javascript inside the definition of a class you can now use the keyword class, example:
class Chef{
  constructor(food){
    this.food = food;
  }
  cook(){
    console.log(this.food)
  }
}

let zhangsan =new Chef(‘eggs’); //eggs

 

Based on an instance of this class is created automatically performs constructor method, you can put some initialization method on constructor inside
This example zhangsan chef can use this class which method

Guess you like

Origin www.cnblogs.com/fe-cherrydlh/p/11118299.html