你如何在Haxe中创建公共常量?我只需要const在AS3中使用旧的模拟:
public class Hello
{
public static const HEY:String = "hey";
}
Run Code Online (Sandbox Code Playgroud)
Gam*_*a11 19
在Haxe中声明常量的常用方法是使用static修饰符.
class Main {
public static inline var Constant = 1;
static function main() {
trace(Constant);
trace(Test.Constant);
}
}
Run Code Online (Sandbox Code Playgroud)
请参阅try.haxe.org.
小智 8
对于非静态变量和对象,可以为它们提供浅常量,如下所示:
public var MAX_COUNT(default, never):Int = 100;
Run Code Online (Sandbox Code Playgroud)
这意味着您可以以"默认"方式读取值,但可以"永不"写入它.
更多信息可以在http://adireddy.github.io/haxe/keywords/never-inline-keywords找到.