Closed
Description
Currently the following is allowed:
enum Color { red, green, blue }
function fun(myColor) {
if (myColor == Color.red) {
console.log("awesome");
} else {
console.log("bummer");
}
}
This compiles, but gives a warning:
function fun(myColor) {
enum Color { red, green, blue } // Warning "Statement expected"
if (myColor == Color.red) {
console.log("awesome");
} else {
console.log("bummer");
}
}
Especially when refactoring existing JavaScript code, there are cases where an enum would be useful, but wouldn't be used outside of a single function. In those cases, I think it makes sense to allow the enum to be defined inside of the function's scope.