Skip to content

Instantly share code, notes, and snippets.

@agrippa1994
Created October 6, 2014 16:13
Show Gist options
  • Save agrippa1994/24c1fd23ce7017f15934 to your computer and use it in GitHub Desktop.
Save agrippa1994/24c1fd23ce7017f15934 to your computer and use it in GitHub Desktop.
JavaScript enumeration
var enumeration = function(initial) {
var _val = initial;
return {
get value() {
return (_val++);
}
};
};
var e1 = enumeration(0);
console.log(e1.value);
console.log(e1.value);
var e2 = e1;
console.log(e2.value);
e2 = enumeration(5);
console.log(e2.value);
@agrippa1994
Copy link
Author

Output

0
1
2
5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment