Haxe 中的局部常量 - 可能

sha*_*hal 0 haxe

我知道Haxe 中有一个关于类属性的常量问题。我的问题是:是否可以在函数内部定义常量?喜欢:

function foo(){
   const bar=7;
   bar = 8; // should prevent compilation
}
Run Code Online (Sandbox Code Playgroud)

也许像 var 之类的var foo:ReadOnlyInt东西?

Gam*_*a11 6

您正在寻找final.

function foo() {
   final bar = 7;
   bar = 8; // not allowed
}
Run Code Online (Sandbox Code Playgroud)

https://haxe.org/manual/expression-var.html