Javascript has a keyword const, but the current browser does not seem to support it. If you must define some constants, you can actually use closures and anonymous functions to define constants.
For example:
Var Class = (function () {var UPPER_BOUND = 100; // defines the constant var Test ={}; // defines a static method to obtain the constant Test. getUPPER_BOUND = function () {return UPPER_BOUND;} return Test ;})();
Usage:
Var k = Class. getUPPER_BOUND (); alert (k );//
When there are multiple constants: You can also write them like 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) {// return constants [name];} return Test })();
Usage:
Var k = Class. getConstant ('Upper _ bound'); alert (k );//