Last active
January 7, 2020 23:30
-
-
Save wdonet/cd439efee1a05e308180d0b0c904c800 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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