Sharing & modifying a variable between multiple files node.js

后端 未结 7 1149
日久生厌
日久生厌 2020-12-04 14:25

main.js

var count = 1;

// psuedocode
// if (words typed begins with @add)
require(\'./add.js\');

// if (words typed begins with @remove)
require(\'./remo         


        
7条回答
  •  佛祖请我去吃肉
    2020-12-04 14:55

    alternatively, to all other answers

    getters & setters

    var _variableThing = 1223
    
    module.exports = {
      get variableThing(){
        return _variableThing
      },
    
      set variableThing(val){
        _variableThing = val
      }
    }
    

    won't work with direct imports though

提交回复
热议问题