COMMUNITY

Constants inside functions


(Shalmu) #1

I’d be happy to

function a(){
  const hey=33;
}

I love immutability. Do you?


#2

Here is final hey = 33; since haxe 4.0 preview 2
There is no documentation yet, but you can learn more here https://github.com/HaxeFoundation/haxe/pull/6596
UPD Oh, this does not work locally, my bad.


(Marcelo Serpa) #3

Why wouldn’t final work for local vars? Was this intentional?


(Shalmu) #4

Hm… So why there is no way to declare immutable variable locally? Is it hard to implement? Is anybody against it?


(Christopher Mandlbaur) #5

Looks like the local implementation is still open to be implemented: https://github.com/HaxeFoundation/haxe/issues/6584