Skip to content

Instantly share code, notes, and snippets.

@ryanfitzer
Forked from jrburke/basic.js
Created Nov 17, 2011
Embed
What would you like to do?
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

ryanfitzer commented Nov 17, 2011

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