Skip to content

Instantly share code, notes, and snippets.

@cbednarski
Created October 9, 2013 10:42
Show Gist options
  • Save cbednarski/6899351 to your computer and use it in GitHub Desktop.
Save cbednarski/6899351 to your computer and use it in GitHub Desktop.
Example of private data in a closure in javascript
var lib = (function (win) {
var sum = 0;
return {
makeSum: function (arr) {
win.document.body;
JSoop.each(arr, function (value, index) {
sum = sum + value;
});
return sum;
}
};
}(window));
lib.makeSum([1, 2, 3]); //6
lib.makeSum([1, 2, 3]); //12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment