我正在尝试使用名称间距系统创建一个 jQuery 插件,所以这是我所拥有的一个小例子
(function($){
var jScrollerMethods = {
init:function(config){
this.settings = $.extend({
'option':'value'
}, config);
},
getOption:function(){
return this.settings.option;
}
}
$.fn.jScroller = function(call){
if ( jScrollerMethods[call] ) {
return jScrollerMethods[call].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof call === 'object' || ! call ) {
return jScrollerMethods.init.apply( this, arguments );
} else {
$.error( 'Method ' + call + ' does not exist on jQuery.jScroller' );
}
}
$(".selector").jScroller({'option':'newValue'});
var opt = $(".selector").jScroller("getOption");
})(jQuery);
该opt
变量不起作用,并且它不应该像在声明这样的函数时this
那样init:function(){..
this
工作保存到窗口,因为在不同的选择器上运行的 jScroller 实例可能不止一个,我似乎只是找到或弄清楚了init
getOption