Skip to content

Instantly share code, notes, and snippets.

@ryanfitzer
Forked from jrburke/basic.js
Created November 17, 2011 05:18
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 ryanfitzer/1372424 to your computer and use it in GitHub Desktop.
Save ryanfitzer/1372424 to your computer and use it in GitHub Desktop.
possible jquery plugin boilerplate
!function( root, factory ) {
// Export
if ( typeof exports === 'object' ) {
// Node/CommonJS
factory( require( 'jquery' ) );
} else if ( typeof define === 'function' && define.amd ) {
// AMD. Use a named plugin in case this
// file is loaded outside an AMD loader,
// but an AMD loader lives on the page.
define( 'myPlugin', [ 'jquery' ], factory );
} else {
// Browser globals
factory( root.jQuery );
}
}( this, function( $ ) {
// Plugin constructor
$.MyPlugin = function( element, options ) {};
// Plugin prototype
$.MyPlugin.prototype = {};
// Plugin to jQuery's prototype
$.fn.myPlugin = function( options ) {
// New instance for each element in the collection.
return this.each( function() {
new $.MyPlugin( this, options );
});
}
});
@ryanfitzer
Copy link
Author

Edited based on my response to the original gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment