Skip to content

Instantly share code, notes, and snippets.

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