Last active
May 9, 2016 19:14
-
-
Save hkfoster/7c91739372c80ab4617337bd1f4515fc to your computer and use it in GitHub Desktop.
A simple boilerplate for UMD JS modules
This file contains 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
/** | |
* MyModule 0.0.1 | |
* A short description of your module | |
* @author Me (@me) | |
* @license MIT | |
*/ | |
;( function( root, factory ) { | |
if ( typeof define === 'function' && define.amd ) { | |
define( factory ); | |
} else if ( typeof exports === 'object' ) { | |
module.exports = factory; | |
} else { | |
root.myModule = factory( root ); | |
} | |
})( this, function( root ) { | |
'use strict'; | |
// Public API function | |
var exports = function( element, settings ) { | |
// Parameter variables | |
var | |
selector = document.querySelector( element ), | |
defaults = { | |
numberVariable: 123, | |
stringVariable: 'abcd' | |
}; | |
// Only run if selector exists | |
if ( !selector ) return false; | |
// Scoped variables | |
var | |
options = compose.extend( defaults, settings ), | |
optVar = options.option; | |
// Plugin logic... | |
}; | |
// Public API | |
return exports; | |
}); | |
// Instantiate | |
myModule( 'element', { | |
numberVariable: 456, | |
stringVariable: 'efg' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment