Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Created August 31, 2015 21:31
Show Gist options
  • Save gartenfeld/f580cd5a6718815a67b9 to your computer and use it in GitHub Desktop.
Save gartenfeld/f580cd5a6718815a67b9 to your computer and use it in GitHub Desktop.
Creating new closure scopes in Node.
module.exports = function () {
var c = [];
return {
push: function (item) {
c.push(item);
},
print: function () {
console.log(c);
}
};
};
var a = require('./module')();
var b = require('./module')();
a.push('argle');
b.print(); // []
a.push('bargle');
a.print(); // ['argle', 'bargle']
b.print(); // []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment