简体   繁体   English

如何检查类是否覆盖ES6中的父方法

[英]How to check if class overides parent methods in ES6

I want to create something like interface in ES6 and I want to force overide methods in base class. 我想在ES6中创建类似接口的内容,并且想在基类中强制覆盖方法。

class DatabaseAPI {
  login() {
     throw new Error('Unimplemented method: login');
  }
}

class UserService extends DatabaseAPI {
  constructor() {
    super();
  }
}

Is there any way to force above error during creating UserService class? 在创建UserService类期间,是否有任何方法可以强制上述错误?

No, there is not. 不,那里没有。 The error will be thrown once login is called. 调用login后将引发错误。

我写了这个包,你可以尝试一下es6-interface

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM