我不确定是什么导致了这个错误,但是没有必要将所有静态方法都放在jQuery原型中。
尝试使用以下方法公开插件:
(function($) {
// The constructor of your plugin:
var imageSlide = function(elems, options) {
this.elems = elems; // the targets from the jQuery selector
this.options = options;
};
// the public inherited methods:
imageSlide.prototype = {
nextSlide: function() {
console.log('nextSlide called');
}
};
// extending the jQuery prototype and returning only one instance:
$.fn.imageSlide = function(options) {
return new imageSlide(this, options);
};
})(jQuery);
现在你可以调用插件,它的方法如下:
var myGallery = $('#gallery').imageSlide();
myGallery.nextSlide();