Haxe中的局部常量-可能

我知道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


以上是Haxe中的局部常量-可能的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>