我试图定义一个函数 attachPicker 可以这样调用:
(function(){
$.fn.tagPicker = function(source){
this.attachPicker();
}
})(jQuery);
我试过:
(function(){
$.fn.tagPicker = function(source){
this.attachPicker();
//define attachPicker
$.fn.attachPicker = function(){
//code here
}
}
})(jQuery);
(function(){
$.fn.tagPicker = function(source){
this.attachPicker();
//define attachPicker
this.attachPicker = function(){
//code here
}
}
})(jQuery);
两人都扔了
Uncaught TypeError: Object [object Object] has no method 'attachPicker'
如果我这样做了
(function(){
$.fn.tagPicker = function(source){
this.attachPicker();
}
$.fn.attachPicker() = function(){ //codes here };
})(jQuery);
有效。但我想在 tagPicker 中定义 attachPicker 以便它可以访问源。任何人都可以解释为什么我尝试过的那些不起作用并给我任何建议?当然,我知道如果在外部定义 attachPicker,我可以将 source 作为参数传递。提前致谢!