我想在a中实现常量class,因为在代码中找到它们是有意义的.
到目前为止,我一直在使用静态方法实现以下解决方法:
class MyClass {
static constant1() { return 33; }
static constant2() { return 2; }
// ...
}
Run Code Online (Sandbox Code Playgroud)
我知道有可能摆弄原型,但许多人建议不要这样做.
有没有更好的方法在ES6类中实现常量?