Skip to content

Instantly share code, notes, and snippets.

@olopsman
Last active January 15, 2023 22:58
Embed
What would you like to do?
Sharing JavaScript Code Across Components in Salesforce, javascript closure pattern.
window._counter = (function() { // this is attached to the window object thus this is a namespace variable
var value = 0; // private
return { //public API
increment: function() {
value = value + 1;
return value;
},
getValue: function() {
return value;
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment