Created
October 6, 2014 16:13
-
-
Save agrippa1994/24c1fd23ce7017f15934 to your computer and use it in GitHub Desktop.
JavaScript enumeration
This file contains 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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output