在扩展类时,有时我们会忘记在已经实现的方法中调用超类实现。
当一个方法被覆盖而不是调用 super 时,有没有办法通过抛出错误或其他东西来防止这种情况发生?
例子
class MainClass implements OnInit
{
ngOnInit() {
// base implementation
}
}
class InnerClass extends MainClass
{
ngOnInit() {
super.ngOnInit(); // ---> throw error if didn't call this line
// additional implementation
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
997 次 |
| 最近记录: |