Created
February 19, 2021 15:30
-
-
Save davidpaulhunt/fd185de6d8811e58da5d4c84c93352eb to your computer and use it in GitHub Desktop.
Node.js Design Patterns - Log Rocket inspired notes
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
// simulate static variable | |
// auto incrementing id generator | |
const idGen = (() => { | |
let id = 0; | |
return () => { | |
id++; | |
return id; | |
}; | |
})(); | |
const id1 = idGen(); // 1 | |
const id2 = idGen(); // 2 | |
idGen(); | |
idGen(); | |
const id4 = idGen(); // 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment