Skip to content

Instantly share code, notes, and snippets.

@klovadis
Created March 6, 2013 12:51
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 klovadis/5099102 to your computer and use it in GitHub Desktop.
Save klovadis/5099102 to your computer and use it in GitHub Desktop.
Configuration of your JavaScript component
Namespace.ModuleName = function (opt) {
// default configuration values
var defaults = {
moduleContextSelector: '.select-an-awesome > .module',
moduleTitle: 'Some Arbitrary Title',
moduleTimeoutSpeed: 3000
}
// local config values
var config = {};
// overwrite defaults with values in opt
if (typeof opt !== 'object') opt = {};
for (var k as v in defaults) {
if (typeof config[k] !== 'undefined')
opt[k] = config[k];
else opt[k] = defaults[k];
}
// return your thing
return ({
/* export functionality here
use scoped config.moduleContextSelector etc
*/
});
}
// create an instance
var instance = Namespace.Modulename({ moduleTitle: 'another title'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment