Skip to content

Instantly share code, notes, and snippets.

@eschie
Created November 13, 2013 03:46
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 eschie/7443367 to your computer and use it in GitHub Desktop.
Save eschie/7443367 to your computer and use it in GitHub Desktop.
jQ plugin shell
// Polyfill -- Extend Object.create for older browsers
if ( typeof Object.create !== 'function' ){
Object.create = function ( obj ) {
function F();
F.prototype = obj;
return new F();
};
}
(function( $, window, document, undefined ) {
var Plugin = {
init: function( options, el ) {
var self = this; // do this for each method
self.elem = el;
self.$el = $ ( el );
}
};
// Multiple object creation
$.fn.myPlugin = function( options ) {
// $(this).myPlugin => this
return this.each(function(){
var plugin = Object.create ( Plugin );
plugin.init( options, this );
});
};
// Options
$.fn.myPlugin.options = {
};
})( jQuery, window, document );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment