Created
October 26, 2014 11:51
-
-
Save rochnyak-d-i/bcd0cdc031fc21bddc48 to your computer and use it in GitHub Desktop.
JS Константы
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var constant = (function() { | |
var | |
constants = {} | |
, ownProp = Object.prototype.hasOwnProperty | |
, allowed = { | |
string: 1 | |
, number: 1 | |
, boolean: 1 | |
} | |
, prefix = (Math.random() + '_').slice(2) | |
; | |
return { | |
set: function(name, value) { | |
if(this.isDefined(name)) { | |
return false; | |
} | |
if(!ownProp.call(allowed, typeof value)) { | |
return false; | |
} | |
constants[prefix + name] = value; | |
return value; | |
} | |
, isDefined: function(name) { | |
return ownProp.call(constants, prefix + name); | |
} | |
, get: function(name) { | |
if(this.isDefined(name)) { | |
return constants[prefix + name]; | |
} | |
return null; | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment