ES6 class

作者: writeanewworld | 来源:发表于2018-09-26 12:17 被阅读0次

1.property语法糖

class  MyTest{
   constructor(age){
      this.name = "王"
      this.age = age
   }
   sayHello(){
      console.log(`hello ${this.name} , my age is ${this.age}`)
   }
}
test = new MyTest(18) 
test.sayHello() 

结果:

image.png

相关文章

网友评论

      本文标题:ES6 class

      本文链接:https://www.haomeiwen.com/subject/yjudoftx.html