Skip to content

Instantly share code, notes, and snippets.

@olopsman
Last active January 15, 2023 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olopsman/5ea4fe771d533048f9a3cd4cd03e9f17 to your computer and use it in GitHub Desktop.
Save olopsman/5ea4fe771d533048f9a3cd4cd03e9f17 to your computer and use it in GitHub Desktop.
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