Static Method
// Animal.js
class Animal {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
static sleep() {
console.log('Zzz');
}
}
export default Animal;// index.js
import Animal from './Animal';
let anim = new Animal('Jake');
Animal.sleep(); // 'Zzz'
anim.sleep(); // Uncaught TypeError: anim.sleep is not a functionLast updated