【发布时间】:2017-06-10 17:53:32
【问题描述】:
我在为 JS 中的子类创建构造函数时遇到了麻烦。类的构造函数工作正常!
//defining base class State
class State {
constructor(){
this.someText = "someText";
}
start(){
}
update(){
}
exit(){
}
}
//defining subclass preloadState
class preloadState extends State{
constructor(){
this.ball = "red";
}
start(){
console.log(this.ball);
}
}
var state = new preloadState;
state.start();
}
运行代码时,我收到错误this.ball is not defined in the preloadState 类。为什么会这样?
【问题讨论】:
标签: javascript class this subclass