Skip to content

Instantly share code, notes, and snippets.

@hunan-rostomyan
Last active July 11, 2016 22:33
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 hunan-rostomyan/fee1e8854f3f1f78ca48a1e99bc8cb9e to your computer and use it in GitHub Desktop.
Save hunan-rostomyan/fee1e8854f3f1f78ca48a1e99bc8cb9e to your computer and use it in GitHub Desktop.
Stateful Functions
var called = (function() {
var count = 0;
return function() {
count++;
console.log(`Called : ${count}`);
};
}());
called(); //=> Called : 1
called(); //=> Called : 2
let called = (() => {
let count = 0;
return () => {
count++;
console.log(`Called : ${count}`);
};
})();
called(); //=> Called : 1
called(); //=> Called : 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment