Created
January 28, 2020 05:02
-
-
Save arcticmouse/7d03c70201699b4265f7782809a6342f to your computer and use it in GitHub Desktop.
techtonica create counter class
This file contains 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
function createCounter(startingValue){ | |
var counter = startingValue | |
var newObject = { | |
getValue: function() { return counter }, | |
increment: function() { return counter++ } | |
} | |
return newObject | |
} | |
let c = createCounter(1) | |
console.log("c.counter =>", c.counter) | |
c.increment() | |
console.log("c.getValue() =>", c.getValue()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment