search

Home  >  Q&A  >  body text

javascript - node cross file access

//a.js
var x = 1;
function up(){
    x++;
}
module.exports.x = x;
module.exports.up = up;
//b.js
var vA = require('./a');
a.up();
console.log(a.x)

//c.js
var vA = require('./a');
a.up();
console.log(a.x)

How to change the x value in a in b.js and c.js in the above three files and share the value of x

我想大声告诉你我想大声告诉你2814 days ago427

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-19 10:33:38

    I know, it’s a matter of writing order

    reply
    0
  • Cancelreply