I tried to define an “enum” using an Object and freeze inside a JS
class in the next manner:
//test.js
class MyClass{
static MyEnum = Object.freeze({
kZero: 0,
kOne: 1
});
}
console.log(MyClass.MyEnum.kZero);
console.log(MyClass.MyEnum.kOne);
When running the html
file in firefox
I get the next output:
0 test.js:8:9
1 test.js:9:9
Uncaught SyntaxError: redeclaration of let MyClass
<anonymous> file:<path>/test.js:1
Can someone please explain what’s wrong or direct me to a source where it’s explained? I read the related posts, but all I could find are cases when let
is indeed used.
The html
file:
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<script src="test.js" charset="utf-8"></script>
<link rel="stylesheet" href="test_styles.css"></link>
<title>Page</title>
</head>
<body>
<script src="test.js"></script>
</body>
</html>
and the css
file it empty.