Created
July 3, 2015 16:30
-
-
Save georgeOsdDev/85da679887b40d503028 to your computer and use it in GitHub Desktop.
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
function* idMaker(prefix){ | |
let idx = 0; | |
while(true){ | |
yield `${prefix}_${idx++}`; | |
} | |
} | |
let users = idMaker("user"); | |
console.log(users.next()) // {"value":"user_0","done":false} | |
console.log(users.next()) // {"value":"user_1","done":false} | |
let items = idMaker("item"); | |
console.log(items.next()) // {"value":"item_0","done":false} | |
console.log(items.next()) // {"value":"item_1","done":false} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment