JQuery 플러그인 상용구

1 개요[ | ]

jQuery Plugin Boilerplate
jQuery 플러그인 상용구
  • 생성자에서 defaults 설정값을 기본으로 사용자의 설정값을 적용하여 init() 호출
사용자가 아무 설정도 안하면 defaults 설정이 될 것이고, 설정을 하면 그 값이 되게 한다...

2 소스 코드[ | ]

JavaScript
Copy
;(function ( $, window, document, undefined ) {
	"use strict";
	var pluginName = "defaultPluginName",
		defaults = {
		propertyName: "value"
	};
	function Plugin ( element, options ) {
		this.element = element;
		this.settings = $.extend( {}, defaults, options );
		this._defaults = defaults;
		this._name = pluginName;
		this.init();
	}
	$.extend(Plugin.prototype, {
		init: function () {
			console.log("xD");
		},
		yourOtherFunction: function () {
		}
	});
	$.fn[ pluginName ] = function ( options ) {
		return this.each(function() {
			if ( !$.data( this, "plugin_" + pluginName ) ) {
				$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
			}
		});
	};
})( jQuery, window, document );

3 같이 보기[ | ]

4 참고[ | ]