Skip to content

Instantly share code, notes, and snippets.

@wdonet
Last active January 7, 2020 23:30
Show Gist options
  • Save wdonet/cd439efee1a05e308180d0b0c904c800 to your computer and use it in GitHub Desktop.
Save wdonet/cd439efee1a05e308180d0b0c904c800 to your computer and use it in GitHub Desktop.
const createCounter = function() {
let count = 0;
this.click = () => count+=1;
this.getCount = () => count.toLocaleString();
}
const counter = new createCounter();
counter.click(); //count=1
counter.click(); //count=2
counter.click(); //count=3
counter.count = 78; //still count is 3
console.log(counter.getCount()); // 3
console.log(JSON.stringify(counter)); // {"count":78}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment