Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidpaulhunt/fd185de6d8811e58da5d4c84c93352eb to your computer and use it in GitHub Desktop.
Save davidpaulhunt/fd185de6d8811e58da5d4c84c93352eb to your computer and use it in GitHub Desktop.
Node.js Design Patterns - Log Rocket inspired notes
// 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