ES6中的静态方法
2019-11-5 张宇童
相比在ES5中的静态方法ES6定义的更加清晰,在ES6中定义一个静态方法只需要一个static关键字
下面请看example
class Animal {
constructor(type) {
this.type = type
}
eat () {
Animal.walk()
console.log('我在吃')
}
static walk() {
console.log('我要走过去')
}
}
(new Animal('小狗')).eat()
标签: javascript ES6 静态方法
发表评论: