-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support const within classes #1243
Comments
In other languages like C# and VB, classes have a class Abc
public shared readonly A_LOCALLY_SCOPED_CONST as string = "def"
end class
Sub Main()
Console.WriteLine(Abc.A_LOCALLY_SCOPED_CONST)
End Sub My gut leans towards implementing it more like that Here's your example modified in a similar way: const THIS_IS_GLOBALLY_AVAILABLE = "abc"
class Abc
static const A_LOCALLY_SCOPED_CONST as string = "def"
function getMeAValue()
return Abc.A_LOCALLY_SCOPED_CONST
end function
end class
print THIS_IS_GLOBALLY_AVAILABLE ' > "abc"
print new Abc().getMeAValue() ' > "def"
print new Abc().A_LOCALLY_SCOPED_CONST ' > invalid
print Abc.A_LOCALLY_SCOPED_CONST ' > "def" Thoughts on this? |
I like that version more 😄 although we'd be introducing a |
I like the idea of introducing I'll refer to TypeScript, as this is my background - in the process of TS transpilation, constant values aren't replaced with direct values, they just follow JS Once we have it defined this way, there is no sense of just
The inspiration was the JavaScript world where you can create e.g. a Date instance using e.g. the
TypeScript too doesn't support enum as a static property. There is a workaround defining a namespace and a class with the same name which, in my opinion, should be possible in Brighterscript too:
Actually, by letting declaring a namespace and a class with the same name, there wouldn't be a necessity for implementing the |
It would be nice to have class-scoped consts which don't pollute the global scope.
The text was updated successfully, but these errors were encountered: