Skip to content

Instantly share code, notes, and snippets.

@makenova
Created August 31, 2015 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makenova/8a8e9478eba1962428c5 to your computer and use it in GitHub Desktop.
Save makenova/8a8e9478eba1962428c5 to your computer and use it in GitHub Desktop.
messing with this and node module.exports
pt = require('./thisy');
pt.printthis();
module.exports = {
printthis: printy,
foo: somefoofunc
};
function printy (){
// if this file is called from within itself(uncomment line 12), this.foo is undefined
this.foo();
// if called from within itself, this is the global node process
// if called outside, through an import, this referrs to the export object
console.log(this);
}
// printy();
function somefoofunc (){
console.log('in some foo func');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment