jQuery插件样板
我想知道你们怎么看待这个样板jQuery插件样板,jquery,Jquery,我想知道你们怎么看待这个样板 ;(function( $, window, document, undefined ) { // plugin's name $.fn.plugin = function(method, options) { // defaults var defaults = { property: "value" }; // overwrites default optio
;(function( $, window, document, undefined ) {
// plugin's name
$.fn.plugin = function(method, options) {
// defaults
var defaults = {
property: "value"
};
// overwrites default options
var settings = $.extend( {}, defaults, method, options );
// methods object
var methods = {
// method's namespace
methodA: function() {
// code goes here
}
};
// return a valid method
if ( methods[method] ) {
return methods[method].apply( this );
} else if ( typeof method === "object" ) {
return methods.fade.apply( this );
} else {
console.error( "Method %d does not exist in jQuery.transition", method );
}
};
})( jQuery, window, document );
它似乎工作得很好,但我不太确定它的性能和良好的实践,尽管它非常类似于jquery的社交创作