ES6 (xii) Classes and Objects

And instance constructors 

class the Person { 
  constructor (name, Age) { 
    the this .name = name
     the this .age = Age 
  } 
} 

the let vPerson = new new the Person ( 'V', 10 ) 
the console.log ( 'Examples and constructors' , vPerson ) 

inheritance 

class Child the extends the Person { 
} 

the console.log ( 'inherited', new new Child ( 'Kaka', 10 )) 

Inheritance transmission parameters 

class the extends the Person {Child 
  constructor (name = 'Child' ) { 
    Super (name) 
    the this .Type = 'Game' 
  } 
} 

the console.log ('继承传递参数', new Child('hello'))

getter  setter

class Person {
  constructor (name = 'kaka', age) {
    this.name = name
    this.age = age
  }

  get longName () {
    return 'hello ' + this.name
  }

  set longName (value) {
    this.name = value
  }
}

let v = new Person()
console.log('getter', v.longName)
v.longName = 'ronle'
console.log('setter', V.longName) 

static method 

class Person { 
  constructor (name = 'Kaka' ) {
     the this .name = name 
  } 

  static Tell () { 
    the console.log ( 'Tell' ) 
  } 
} 
Person.tell () 

static property 

class Person { 
  constructor (name = 'Kaka' ) {
     the this .name = name 
  } 
} 
Person.type = 'Game' 
the console.log ( 'static properties', Person.type)

 

Guess you like

Origin www.cnblogs.com/ronle/p/11563991.html