// ============================================= //
// Enums Pseudo Module Definition
// ============================================= //
var Enums = (function(){
var exports = {};
// ============================================= //
// EnumType Type Definition
// ============================================= //
// Api is modeled largely after Swift enums
// Of course JS as it is offers no real immutability,
// but I like how convenient Swift Enums are
// and thought this might be a nice convention for
// "Enum" like things.
var EnumValue = function(namedParams) {
namedParams = namedParams || {};
this._rawValue = namedParams.rawValue;
this._value = namedParams.value;
this._key = namedParams.key;
};
EnumValue.extend = function() {
// super simple extend
// see: http://stackoverflow.com/a/10430875
var Type = function(namedParams) {
EnumValue.call(this, namedParams);
}
Type.prototype = EnumValue.prototype;
Type.prototype.constructor = Type;
return Type;
};
EnumValue.prototype.getValue = function () {
return this._value;
};
EnumValue.prototype.getRawValue = function () {
return this._rawValue;
};
EnumValue.prototype.value = function () {
// special sugar method to make getting value more convenient
return this._rawValue || this._value;
};
EnumValue.prototype.toString = function () {
return this._key;
};
var EnumType = function(options, ValueType) {
this.ValueType = ValueType || EnumValue;
_.extend(this, this.enumerate(options));
};
EnumType.prototype.enumerate = function(options) {
if(_.isArray(options)) return this.enumerateAssociative(options);
if(_.isObject(options)) return this.enumerateRaw(options);
};
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.