Last active
November 3, 2015 10:25
-
-
Save ville6000/a565fac5055797b7ae66 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
function Counter () { | |
var count = 0; | |
function logNewValue() { | |
console.log("Count is " + count); | |
} | |
return { | |
add: function () { | |
count += 1; | |
}, | |
decrease: function () { | |
count -= 1; | |
}, | |
value: function () { | |
logNewValue(); | |
} | |
} | |
} | |
var c1 = new Counter(); | |
var c2 = new Counter(); | |
c1.add(); | |
c1.add(); | |
c1.add(); | |
c1.decrease() | |
c1.value(); // Count is 2 | |
console.log(c1.count); // undefined | |
console.log(typeof c1.logNewValue); // undefined | |
c2.add(); | |
c2.decrease(); | |
c2.decrease(); | |
c2.value(); // Count is -1 | |
console.log(c2.count); // undefined | |
console.log(typeof c2.logNewValue); // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment