Javascript 我的jQuery插件返回中定义的方法';错误:undefined不是一个函数?
我有以下代码,我得到了错误Javascript 我的jQuery插件返回中定义的方法';错误:undefined不是一个函数?,javascript,jquery,Javascript,Jquery,我有以下代码,我得到了错误uncaughttypeerror:undefined不是一个函数(重复了8次),对于它定义的方法\u setProgress() 我的插件代码如下: ;( function($, window, document, undefined) { var pluginName = "imageSlider2"; var defaults = { onImagesLoaded : undefine
uncaughttypeerror:undefined不是一个函数(重复了8次)
,对于它定义的方法\u setProgress()
我的插件代码如下:
;(
function($, window, document, undefined)
{
var pluginName = "imageSlider2";
var defaults = {
onImagesLoaded : undefined,
onComplete : undefined
};
var max_image_height = null;
function Plugin(element, options)
{
this.element = element;
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this._init();
}
Plugin.prototype = {
_init : function()
{
$(document).on(
'images-loaded',
function(e)
{
//_hideProgress();
}
);
$(document).on(
'slides-initiated',
function(e)
{
//_animationStart();
}
);
this._hideAny();
this._addProgress();
},
_hideAny : function()
{
...
},
_randomID : function()
{
...
},
_addProgress : function()
{
...
// This method just injecting an HTML element in my document
this._imagePreload()
},
_setProgress : function(progress)
{
...
},
_imagePreload : function()
{
...
$percent = 25;
this._setProgress($percent);
...
}
};
$.fn[pluginName] = function(options)
{
var plugin;
this.each(
function()
{
plugin = $.data(this, "plugin_" + pluginName);
if(!plugin)
{
plugin = new Plugin(this, options);
$.data(this, "plugin_" + pluginName, plugin);
}
}
);
return plugin;
};
}
)(jQuery, window, document);
我高度怀疑,因为您覆盖了整个原型,因此缺少构造函数。最好尝试单独分配原型方法,如
Plugin.prototype._init = function(){}
或
再次将构造函数设置为
Plugin.prototype.constructor = Plugin;
这将解决我的问题,还是对我的插件来说是一个更好的结构?