Skip to content

Instantly share code, notes, and snippets.

@island205
Last active December 14, 2015 12:58
Show Gist options
  • Save island205/5089778 to your computer and use it in GitHub Desktop.
Save island205/5089778 to your computer and use it in GitHub Desktop.
// File: global.js
var timestamp = new Date()
exports.global = {
timestamp: timestamp
}
console.log('timestemp from global.js is ' + timestamp)
// File: foo.js
var _global = require('./global').global
console.log('timestemp from foo.js is ' + _global.timestamp)
console.log('change timestamp to ' + (_global.timestamp = new Date()))
// File: bar.js
var _global = require('./global').global
require('./foo')
console.log('timestemp from bar.js is ' + _global.timestamp)
// git bash
// node bar.js
// timestemp from global.js is Tue Mar 05 2013 19:42:21 GMT+0800 (中国标准时间)
// timestemp from foo.js is Tue Mar 05 2013 19:42:21 GMT+0800 (中国标准时间)
// change timestamp to Tue Mar 05 2013 19:42:21 GMT+0800 (中国标准时间)
// timestemp from bar.js is Tue Mar 05 2013 19:42:21 GMT+0800 (中国标准时间)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment