define = (function(){ // Defines a named constant
//
// + original by: Andrea Giammarchi (http://webreflection.blogspot.com)
function toString(name, value){
return "const " + name + "=" + (
/^(null|true|false|(\+|\-)?\d+(\.\d+)?)$/.test(value = String(value)) ? value : '"' + replace(value) + '"'
)
};
var define, replace;
try{
eval("const e=1");
replace = function(value){
var replace = {"\x08":"b","\x0A":"\\n","\x0B":"v","\x0C":"f","\x0D":"\\r",'"':'"',"\\":"\\"};
return value.replace(/\x08|[\x0A-\x0D]|"|\\/g, function(value){return "\\"+replace[value]})
};
define = function(name, value){
var script = document.createElement("script");
script.type = "text/javascript";
script.appendChild(document.createTextNode(toString(name, value)));
document.documentElement.appendChild(script);
document.documentElement.removeChild(script);
}
}
catch(e){
replace = function(value){
var replace = {"\x0A":"\\n", "\x0D":"\\r"};
return value.replace(/"/g, '""').replace(/\n|\r/g, function(value){return replace[value]})
};
define = this.execScript ?
function(name, value){
execScript(toString(name, value), "VBScript");
}:
function(name, value){
eval(toString(name, value).substring(6));
}
};
return define;
})();