Javascript does not have enums. So how can we get the same benefits?
Enum.js is a simple class which gives you enum-like behaviour.
Example: Instead of writing e.g.
if (sibling == 'BROTHER') ...
throughout your code, write Sibling = new Enum('BROTHER SISTER');
then use if (Sibling.isBROTHER(x)) ...
. Here's the Enum.js code as a gist
No comments:
Post a Comment