是否可以声明一个类具有某些功能而不实现它们?
我需要这个,因为我创建了一个类,然后将该类传递给添加了几个函数的 js 框架。我也希望能够调用这些函数,而无需重新实现它们、重定向或强制转换或其他任何方式。
例子:
//example class
class AppComponent {
constructor() {}
}
//create class
var comp: AppComponent = new AppComponent();
//hand over to framework
fw.define("Component", comp);
//now I want to be able to call the added functions such as:
comp.setModel(/*some model*/);
最佳答案
您可以声明函数而不实现它。
//example class
class AppComponent {
constructor() { }
setModel: () => void;
}
//create class
var comp: AppComponent = new AppComponent();
//hand over to framework
fw.define("Component", comp);
//now I want to be able to call the added functions such as:
comp.setModel(/*some model*/);
关于class - typescript :声明函数而不实现它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44653623/