我正在尝试设置我的插件以接受内部的回调函数作为选项参数:
(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);
但是我收到一个错误,即 call() 未定义。我的代码有什么问题?
好的,我将其更改为:
(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);
并且错误仍然存在...