Search found 1 match

by dunufoku
Wed Aug 15, 2018 12:58 pm
Forum: Javascript
Topic: How to use constant in javascript?
Replies: 4
Views: 6720

Re: How to use constant in javascript?

Try this
var CONFIG = (function() {
var private = {
'MY_CONST': '1',
'ANOTHER_CONST': '2'
};

return {
get: function(name) { return private[name]; }
};
})();

alert('MY_CONST: ' + CONFIG.get('MY_CONST')); // 1

CONFIG.MY_CONST = '2';
alert('MY_CONST: ' + CONFIG.get('MY_CONST')); // 1

CONFIG ...