Javascript jQuery插件回调函数参数

Javascript jQuery插件回调函数参数,javascript,jquery,function,Javascript,Jquery,Function,我正在寻找一种更好的方法来访问/管理插件回调函数中的数据。 我想做与jQueryUI相同的事情 UI示例:(我希望如何执行此操作) 我的插件示例(我现在如何拥有它): 这应该能奏效 $( ".selector" ).myplugin({ activate: function( event, object ) {//to much parameters alert(object.item) alert(object.position) alert(object.

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

UI示例:(我希望如何执行此操作)

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


这应该能奏效

$( ".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});
}

这应该能奏效

$( ".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});
}

如果不知道用户从何处获取项目/位置/偏移属性,就很难给出可靠的答案。你能用一个物体做这个吗?然后用户可以传递一个元素或一个声明的对象?如果不知道用户从何处获取item/pos/offset属性,就很难给出可靠的答案。你能用一个物体做这个吗?然后用户可以传递元素或声明的对象?
$( ".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});
}