Skip to content

Instantly share code, notes, and snippets.

@reime005
Created December 27, 2020 21:30
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 reime005/d445effbb89bb68d7267ae231c55f178 to your computer and use it in GitHub Desktop.
Save reime005/d445effbb89bb68d7267ae231c55f178 to your computer and use it in GitHub Desktop.
const chain = () => {
let str = 't'; // 'var' also possible
return input => {
str += input;
return str;
};
};
const t = chain();
console.log(t('e')); // prints 'te'
console.log(t('st')); // prints 'test'
console.log(str); // ReferenceError: str is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment