How to use constant in javascript?
Posted: Tue Feb 09, 2016 2:32 pm
I know how to use variables, pointers and functions but how to add constants to javascript?
- a basic to master the web -
https://forums.spiderbasic.com/
I see, that's a pitty.Fred wrote:You mean PureBasic constants ? If yes, it's not possible, as it's resolved by the compiler before generating the JS.
Code: Select all
Procedure Some()
const.s = #myconstant
!document.title= v_const
EndProcedure
Code: Select all
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.private.MY_CONST = '2'; // error
alert('MY_CONST: ' + CONFIG.get('MY_CONST')); // 1