es5:
let Person = function (type) {
this.type = type
}
// 静态方法
Person.breathe = function () {
console.log('breathing')
}
// 原型上的方法
Person.prototype.speak = function () {
Person.breathe()
console.log('hhhhhh')
}
let student = new Person('student')
student.speak()
// breathing
// hhhhhh
es6:
class Person {
constructor (type) {
this.type = type
}
// 静态方法
static breathe () {
console.log('breathing')
}
// 原型上的方法
speak = function () {
Person.breathe()
console.log('hhhhhh')
}
}
let student = new Person('student')
student.speak()
// breathing
// hhhhhh