Classes are a new feature in ES6, and generally refer to a particular class. How he uses it:
- Create a class
class name { body }
- Use constructor to create properties and methods
Class name {constructor(constructor(name,age)){this.name = 'zhang3'; This.age = 18} // This is the method say(){console.log('123')}}Copy the code
- Instantiate create object
Var ObjName = new class name()
Class inheritance
- extend
Class Father {} calss Son extends Father {} var dd = new Son (Copy the code
- super
The super keyword can call the constructor of the superclass as well as ordinary functions of the superclass, but it is a subclass based on extend
class Father { //body ask(){ console.log('lalala') } } calss Son extends Father { say(){ console.log(super.ask()+'123') //super.ask() is a call to the method in the parent class}} var dd = new Son ()Copy the code