-
-
Save lexoyo/d0f28c4b2c566f91140e to your computer and use it in GitHub Desktop.
Enum-like structure in es2015
This file contains hidden or 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
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