gpt4 book ai didi

class - typescript :声明函数而不实现它们

转载 作者:搜寻专家 更新时间:2023-10-30 21:10:31 26 4
gpt4 key购买 nike

是否可以声明一个类具有某些功能而不实现它们?

我需要这个,因为我创建了一个类,然后将该类传递给添加了几个函数的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com