考虑这个模块:如何打字稿
export module Example{
let customer : any;
export function myExample(customer: string) {
// How to reference the module level customer object here?
// Is there a standard to make these module level variables Pascal Case to prevent this overlap?
}
}
在myExample
功能customer
是一个字符串。我如何参考模块级别customer
?
如果这是一个类,我可以使用this.customer
但this
没有一个模块在工作,并且Example.customer
也不管用,除非客户是出口......
据@RyanCavanaugh http://stackoverflow.com/questions/13255158/when- (这是从2012年开始的,所以它可能已经改变了)'如果你将要有多个实例与每个实例相关联的数据,那么class就是方式去。如果你只是将逻辑连接的无状态函数组合在一起,那么模块就更合适了。“对于我的实际应用,在这个例子中,模块更有意义。 – Daryl
授予。那么常客的做法是什么?这不是无国籍的功能?这意味着你正试图用一个常量值来组合一个无状态函数? – blorkfish
不知道为什么它很重要。现在我把它改成了任何一个。 – Daryl