JS has a keyword const, but the current browser does not seem to support, if you must define some constants, you can actually use closures, anonymous functions to implement the definition of constants.
For example:
var Class = (function () { var upper_bound = 100;//defines the constant var test={}; Defines a method for obtaining constants in a static method Test.getupper_bound=function () { return upper_bound; } return Test;}) ();
Usage:
var k=class.getupper_bound (); Alert (k);//
In the case of multiple constants: You can also write this:
var Class = (function () { //Private static attributes. var constants = {//defines two constants upper_bound:100, lower_bound: -100 } var test={}; Defines a static method Test.getconstant=function (name) {//Get constant Method return constants[name]; } Return Test}) ();
Usage:
var k=class.getconstant (' Upper_bound '); Alert (k);//