1

我想知道你们对这个样板的看法?

;(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 官方创作

4

0 回答 0