3 ms·
I think using require would do the trick. Something along the line like: /* foo.js / var date = new Date(); exports.Date = date; / bar.js / var foo = requi
by _pdeschen 16y ago
I think using require would do the trick. Something along the line like:
/* foo.js /
var date = new Date();
exports.Date = date;
/ bar.js /
var foo = require('./foo.js');
exports.Date = foo.Date;
/ foobar.js */
var foo = require('./foo.js');
var bar = require('./bar.js');
console.log(foo.Date);
console.log(bar.Date)
> console.log(foo.Date);
Sat, 09 Apr 2011 01:05:12 GMT
> console.log(bar.Date)
Sat, 09 Apr 2011 01:05:12 GMT
We are dealing with the same date variable between modules.
[edited. not a good place to share code. gist over github: https://gist.github.com/910994 https://gist.github.com/910994]