Skip to content

Instantly share code, notes, and snippets.

@bmavity
Created February 16, 2011 23:57
Show Gist options
  • Save bmavity/830599 to your computer and use it in GitHub Desktop.
Save bmavity/830599 to your computer and use it in GitHub Desktop.
var ext = require('./sampleExternal');
// In node.js, there is a global object called
// global (go figure)
console.log(global); // empty object
// This is defined in the external JavaScript file
// outside of a function, and with the var keyword
console.log(global.outsideFunctionWithVar); // undefined
console.log(ext.outsideFunctionWithVar); // undefined
// This is defined in the external JavaScript file
// inside of a function, and without the var keyword
console.log(global.insideFunctionWithoutVar); // 'hippo'
console.log(ext.insideFunctionWithoutVar); // undefined
// This is defined in the external JavaScript file
// inside of a function, and with the var keyword
console.log(global.insideFunctionWithVar); // undefined
console.log(ext.insideFunctionWithVar); // undefined
var thisFile = 'on it';
console.log(global.thisFile); // undefined
console.log(thisFile); // 'on it'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment