Last active
August 29, 2015 14:27
-
-
Save storskegg/b35fdb54049b8880aa79 to your computer and use it in GitHub Desktop.
A Method to Produce Constants in ES5
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
// A small function that allows the creation of constants in ES5. | |
// Arguments: | |
// name <String>: The name of your constant | |
// value <Any>: The value of your constant | |
// isEnumerable <Bool>: Should your constant be enumerable? optional, defaults to true | |
// scope <Object>: The scope to which the constant is bound. optional, defaults to window (global) | |
var Const = function (name, value, isEnumerable, scope) { | |
"use strict"; | |
if (isEnumerable === undefined) { | |
isEnumerable = true; | |
} | |
if (scope === undefined) { | |
scope = window; | |
} | |
var properties = {}; | |
properties[name] = { | |
value: value, | |
enumerable: isEnumerable | |
}; | |
Object.defineProperties(scope, properties); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment