Skip to content

Instantly share code, notes, and snippets.

@dotnetCarpenter
Created March 4, 2011 10:15
Show Gist options
  • Save dotnetCarpenter/854427 to your computer and use it in GitHub Desktop.
Save dotnetCarpenter/854427 to your computer and use it in GitHub Desktop.
Enumerates in js
//http://jsfiddle.net/dotnetCarpenter/47KmD/6/
var dir = {
up: 1,
right: 2,
down: 4,
left: 8,
other: 16
};
function transDir(en) {
switch (en) {
case dir.up | dir.down:
return ('up and down');
// break;
case dir.up | dir.right | dir.other:
return ('up, right and other');
// break;
case dir.left:
return 'just left';
default:
return (en);
}
}
function output(a, b){
a.innerHTML += a.innerHTML = b + '\n<br />';
}
var p = document.getElementById('output');
p.innerHTML = '';
output(p, transDir(dir.up | dir.right | dir.other));
output(p, transDir(dir.up | dir.down));
output(p, transDir(dir.left | dir.left)); // it's still just left
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment