Skip to content

Instantly share code, notes, and snippets.

@lexoyo
Forked from MikeFielden/index.js
Last active October 9, 2015 12:46
Show Gist options
  • Save lexoyo/d0f28c4b2c566f91140e to your computer and use it in GitHub Desktop.
Save lexoyo/d0f28c4b2c566f91140e to your computer and use it in GitHub Desktop.
Enum-like structure in es2015
const Shape = {
Triangle: new Symbol()
};
// Demo func
function getArea(shape, options) {
var area = 0;
switch (shape) {
case Shape.Triangle:
area = .5 * options.w * options.h;
break;
}
return area;
}
getArea(Shape.Triangle, {w: 100, h: 50});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment