Where to declare class constants?

后端 未结 9 1463
悲&欢浪女
悲&欢浪女 2021-02-18 14:26

I\'m using class members to hold constants. E.g.:

function Foo() {
}

Foo.CONSTANT1 = 1;
Foo.CONSTANT2 = 2;

This works fine, except that it see

9条回答
  •  猫巷女王i
    2021-02-18 14:53

    Also with namespaces

    var Constants = {
        Const1: function () {
            Const1.prototype.CONSTANT1 = 1;
            Const1.prototype.CONSTANT2 = 2;
        },
    
        Const2: function () {
            Const2.prototype.CONSTANT3 = 4;
            Const2.prototype.CONSTANT4 = 3;
        }
    };
    

提交回复
热议问题