最近撸react 看到了es6 extends的写法 想深入摸一摸 面向对象继承相关的东西
老夫之前写php的时候 类内的属性和方法同名没事啊 子类或自动覆盖父类的啊
然后!! js这里竟然报错了 究其原因是因为 js不支持方法和属性重名。。
class parent{
constructor(props) {
this.repeat = 'parent'
}
}
class child extends parent{
constructor(){
super()
console.log(this.a)
}
repeat(){
console.log(2)
}
}
let c = new child();
c.repeat() //output: Uncaught TypeError: c.repeat is not a function
来源:oschina
链接:https://my.oschina.net/u/4125329/blog/4319396