Created
August 31, 2015 21:31
-
-
Save gartenfeld/f580cd5a6718815a67b9 to your computer and use it in GitHub Desktop.
Creating new closure scopes in Node.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function () { | |
var c = []; | |
return { | |
push: function (item) { | |
c.push(item); | |
}, | |
print: function () { | |
console.log(c); | |
} | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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