Skip to content

Instantly share code, notes, and snippets.

@Dromediansk
Last active December 10, 2019 07:35
Show Gist options
  • Select an option

  • Save Dromediansk/4e33b74c58b3e0da04d2d2a924f8d8a9 to your computer and use it in GitHub Desktop.

Select an option

Save Dromediansk/4e33b74c58b3e0da04d2d2a924f8d8a9 to your computer and use it in GitHub Desktop.
Data encapsulation with closure
const monitorProductivityTime = () => {
let timeWithoutReset = 0;
const productivityTime = () => timeWithoutReset++;
const totalProductivityTime = () => timeWithoutReset;
const reset = () => {
timeWithoutReset = -1;
return 'production time has been restarted!';
}
setInterval(productivityTime, 1000);
return {
totalProductivityTime,
reset
}
}
const holdTime = monitorProductivityTime();
holdTime.totalProductivityTime();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment