Node Modules - exporting a variable versus exporting functions that reference it?

前端 未结 3 2014
粉色の甜心
粉色の甜心 2021-02-09 05:48

Easiest to explain with code:

##### module.js
var count, incCount, setCount, showCount;
count = 0; 

showCount = function() {
 return console.log(count);
};
incC         


        
3条回答
  •  离开以前
    2021-02-09 05:56

    Correct me if I am wrong, but numbers are immutable types. When you change the value of count then your reference changes too. So exports.count references to the old count value.

提交回复
热议问题