Skip to content

Instantly share code, notes, and snippets.

@tfanme
Created February 8, 2018 08:10
Show Gist options
  • Save tfanme/e086b7f0b71f240262f93745f1509e82 to your computer and use it in GitHub Desktop.
Save tfanme/e086b7f0b71f240262f93745f1509e82 to your computer and use it in GitHub Desktop.
一个典型的闭包 + IIFE(Immediately-invoked function expression) F结合的例子
/**
* 一个典型的闭包 + IIFE(Immediately-invoked function expression) F结合的例子
*/
const generateId = (() => {
let i = 0;
return (prefix = '') => {
i += 1;
return `${prefix}${i}`;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment