我试图建立我的插件里面接受一个回调函数作为选项参数:呼叫未定义
(function($) {
$.fn.MyjQueryPlugin = function(options) {
var defaults = {
onEnd: function(e) {}
};
var settings = $.extend({}, defaults, options);
return this.each(function() {
// do stuff (complete() gets called here)
});
};
function complete(e){
settings.onEnd.call(this); // <- the error?
}
})(jQuery);
但我得到调用()是未定义的一个错误。我的代码有什么问题?
好吧,我改变了这个:
(function($) {
$.fn.MyjQueryPlugin = function(options) {
var defaults = {
onEnd: function(e) {}
};
var settings = $.extend({}, defaults, options);
var complete = function(e){
settings.onEnd.call(this); // <- the error?
}
return this.each(function() {
// do stuff (complete() gets called here)
});
};
})(jQuery);
和错误仍然存在......
在你的问题中引用错误会很有用。 – alex 2011-04-26 08:30:15
[It works for me](http://jsfiddle.net/alexdickson/pwF5k/)。 – alex 2011-04-26 08:31:37
是的,这个问题出现在另一个使用call()的函数中,并且忘记改变它:D – Alex 2011-04-26 08:38:40