jQueryプラグインのひな形

jQueryプラグインを作成するためのひな形はネットで調べるといくつかパターンが出てきますが、例えばこういうのはどうでしょうか。

;(function($){

$.fn.myPlugin = function(options) {

     'use strict';

    if (this.length === 0){
    	var error_css  = 'background: #ff0000; color: #FFF; padding: 2px; line-height: 1.5;';
    	console.log('%cERROR( jquery.myPlugin.js ) :DOM Object not found', error_css);
    	return this;
    }

    // private variables
    var priOne = '';
    var priTwo = '';

    // private methods
    var foo = function() {
    };

    // public variables
    this.pubOne = 0;

    // public methods
    this.initialize = function() {
		return this.each(function(i, elem) {
			// ...
    	});
    };

    return this.initialize();
};
})(jQuery);

有名なテンプレートとしては jquery boilerplate があります

● jquery boilerplate

https://jqueryboilerplate.com/

関連エントリー

No.1040
12/15 15:18

edit

jQuery