0

I know there is this question Constants in Haxe about class properties. My question is: is it possible to define constants inside functions? Like:

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

Maybe anything like var var foo:ReadOnlyInt or something?

shal
  • 2,854
  • 4
  • 20
  • 31

1 Answers1

6

You're looking for final.

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

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

Gama11
  • 31,714
  • 9
  • 78
  • 100