Haxe 中的局部常量 - 可能

Local constants in Haxe - possible

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

function foo(){
   const bar=7;
   bar = 8; // should prevent compilation
}

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

您正在寻找 final

function foo() {
   final bar = 7;
   bar = 8; // not allowed
}

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