我无法弄清楚我在这个插件中做错了什么,
(function($){
var methods = {
defaults: function(options) {
// Default options.
var defaults = {
setup: {
tester1: "hello1",
tester2: "hello2",
tester3: "hello3"
},
tester: "hello world"
}
// Always leave this line here.
var options = $.extend(defaults, options);
alert(options.setup.tester2);
// Return the processed options.
return options;
},
init : function( options ) {
var $this = this;
var o = $this.plugin('defaults',options);
},
something : function( options ) {
}
};
$.fn.plugin = function( method ) {
// @reference: http://docs.jquery.com/Plugins/Authoring#Namespacing
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments ); // always change 'init' to something else if you different method name.
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.plugin' );
}
return this;
};
})(jQuery);
所以,
jQuery().plugin(); // return 'hello2' --> correct
但,
jQuery().plugin({setup:{tester1:"x"}}); // return 'undefined' --> should be 'hello2'
有什么想法我应该做什么或我错过了什么?