Skip to content

Instantly share code, notes, and snippets.

@jimbojw
Created February 1, 2010 11:49
Show Gist options
  • Save jimbojw/291635 to your computer and use it in GitHub Desktop.
Save jimbojw/291635 to your computer and use it in GitHub Desktop.
var sys = require('sys');
sys.puts("Top level");
sys.puts(" this === GLOBAL: " + (this === GLOBAL)); // false
sys.puts(" this === exports: " + (this === exports)); // true
var x = "1"; // local variable
sys.puts(" x === GLOBAL.x: " + (x === GLOBAL.x)); // false
sys.puts(" x === exports.x: " + (x === exports.x)); // false
this.y = "2"; // property of this
sys.puts(" this.y === GLOBAL.y: " + (this.y === GLOBAL.y)); // false
sys.puts(" this.y === exports.y: " + (this.y === exports.y)); // true
(function(){ // anonymous function
sys.puts("Inside function");
sys.puts(" this === GLOBAL: " + (this === GLOBAL)); // true
sys.puts(" this === exports: " + (this === exports)); // false
this.z = "3"; // property of this
sys.puts(" this.z === GLOBAL.z: " + (this.z === GLOBAL.z)); // true
sys.puts(" this.z === exports.z: " + (this.z === exports.z)); // false
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment