Last active
November 5, 2016 08:46
-
-
Save balintsera/3db7878fe4b91fe41313cfe74a479b9b to your computer and use it in GitHub Desktop.
Self Executing Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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