jQuery插件回调函数参数

我正在寻找一种更好的方式来访问/管理插件回调函数内的数据。 我想做与jQuery UI相同的事情。

UI示例:(我想怎么做) http://api.jqueryui.com/sortable/

$( ".selector" ).sortable({ activate: function( event, ui ) { alert(ui.item) alert(ui.position) alert(ui.offset) } }); 

我的插件示例(我现在如何拥有它):

 $( ".selector" ).myplugin({ activate: function( event, item, postion, offset ) {//to much parameters alert(item) alert(position) alert(offset) } }); //inside the plugin var varItem = ''; var varPosition = ''; var varOffset = ''; if(typeof self.o.activate == 'function'){ self.o.activate.call(this, varItem, varPosition, varOffset); } 

这应该可以解决问题

 $( ".selector" ).myplugin({ activate: function( event, object ) {//to much parameters alert(object.item) alert(object.position) alert(object.offset) } }); //inside the plugin var varItem = ''; var varPosition = ''; var varOffset = ''; if(typeof self.o.activate == 'function'){ self.o.activate.call(this, {item: varItem, position: varPosition, offset: varOffset}); }