Skip to content

Instantly share code, notes, and snippets.

@balintsera
Last active November 5, 2016 08:46
Show Gist options
  • Save balintsera/3db7878fe4b91fe41313cfe74a479b9b to your computer and use it in GitHub Desktop.
Save balintsera/3db7878fe4b91fe41313cfe74a479b9b to your computer and use it in GitHub Desktop.
Self Executing Function
// Self executing function base form
const CartOps = (function(injectedDependency) {
// public (see api)
const config = {
selectors: {
addToCartForm: '.add-to-cart-form',
},
};
// private (missing from api)
const injDep = injectedDependency;
// run init tasks SEF way (like a constructor)
(function() {
console.log('running');
})();
/*
* Please comment your methods
* Docbloc is preferred but anything counts :)
* @param {string} message the message to dump
* @return {bool} true always returns true
*/
const dump = function(message) {
// Use dependency - OK, possibly not pure
injDep.run();
console.log(config.selectors.addToCartForm + ' ' + message);
return true;
};
// Expose your API (if needed). But go with full private then expose what really needed
return {
dump,
config
};
})($);
// CartOps.dump('message');
// CartOps.config.selectors.addToCartForm; // access config from outside
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment