Skip to content

Instantly share code, notes, and snippets.

@mrosati84
Created November 13, 2012 14:12
Show Gist options
  • Save mrosati84/4065961 to your computer and use it in GitHub Desktop.
Save mrosati84/4065961 to your computer and use it in GitHub Desktop.
Test closure
(function () {
var myObject = (function () {
var privateMember = 0;
// Return public methods
return {
init: function () {
},
getSum: function (add) {
return (privateMember + add);
},
setPrivateMember: function (newPrivateMember) {
privateMember = newPrivateMember;
}
};
}());
myObject.init();
myObject.setPrivateMember(100);
console.log(myObject.getSum(20));
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment