In JavaScript, functions and objects (including arrays) are assigned to variables by reference, and strings and numbers are assigned by value, that is, by creating a copy. If var a = 1 and var b = a and b++ , a will still be 1.
In this line:
exports.count = count;
You made a copy of the value of the count variable. The operations setCount (), incCount (), and showCount () operate on the count variable inside the closure, so m.count will not be affected again. If these variables worked on this.count, then you will get the expected behavior, but you probably don't want to export the count variable anyway.
source share