JS 面向对象2
原创
©著作权归作者所有:来自51CTO博客作者富坚老贼的原创作品,请联系作者获取转载授权,否则将追究法律责任
es6增加class关键字
class Student{
constructor(name1){
this.name1=name1
}
fav(){
return this.name1
}
}
let s=new Student('li')
console.log(s.fav())
class语法糖根本上还是原型
function Student(name1){
this.name1=name1
}
Student.prototype.fav=function(){
return this.name1
}
静态
class Student {
static fav() {
return 'abc'
}
}
console.log(Student.fav())
继承
class Person{
eat(){console.log('eee')}
}
class Student extends Person {}
new Student().eat()