// ============================================= //
// Enums Pseudo Module Definition
// ============================================= //
var Enums = (function() {
var exports = {};
// ============================================= //
// EnumType Type Definition
// ============================================= //
EnumType = function(rawValue) {
/*
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.
see: http://apple.co/1POMrMr for Swift Enum Ref
*/
this._rawValue = rawValue;
};
EnumType.prototype.getRawValue = function () {
return this._rawValue;
};
EnumType.prototype.getValue = function () {
return this._associatedValue;
};
EnumType.prototype.setValue = function (value) {
this._associatedValue = value;
};
// ============================================= //
// Enumerate Utility Function
// ============================================= //
var enumerate = function(options) {
/*
enumerate utility (above) lets us create a signature
that comes as close to the Swifty type definition
I went with a simple funciton for enumerate because
it didn't make much sense to make a custom type
just to make this look a little more OO.
*/
return _.object(
_.map(options, function (value, key, src) {
return [key, new EnumType(value)];
})
);
};
exports.enumerate = enumerate;
return exports;
})();
// ============================================= //
// Demo
// ============================================= //
var Demo = (function(){
var exports = {};
exports.run = function() {
...
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.