从Typescript中的类实例中调用静态函数[duplicate]

问题描述 投票:0回答:1
如何从实例化的类变量调用静态函数?

示例:

class Foo { static Bar() { console.log("Bar"); } } let i = new Foo(); i.Bar() // Not working // Something like this? i.toClass().Bar();

javascript typescript oop
1个回答
0
投票
由于Bar是静态的,因此您可以简单地使用类名Foo来调用它

Foo.Bar();

© www.soinside.com 2019 - 2024. All rights reserved.