【发布时间】:2021-10-05 01:17:12
【问题描述】:
反应原生。在子类中, super.method 未定义。为什么父类方法在super中不可见?
export class ParentClass {
constructor(field) {
this.field = field;
}
protected ruleMatch = (type: string): string => {
return type;
}
onGetRule = (type: string) => {
return this.ruleMatch(type);
}
}
export class ChildrenClass extends ParentClass {
// extends method of parent Class
onGetRule = (type: string) => {
if(type === 'typeA') {
return 'anything';
}
return super.onGetRule(type); // TypeError: Cannot read property 'call' of undefined
}
}
【问题讨论】:
标签: javascript class extends