gpt4 book ai didi

javascript - 我的 jQuery 插件中定义的方法返回错误 : undefined is not a function?

转载 作者:行者123 更新时间:2023-12-03 12:36:35 25 4
gpt4 key购买 nike

我有以下代码,并且我收到方法 _setProgress() 的错误 Uncaught TypeError: undefined is not a function (repeated 8 times)已定义。

我的插件代码如下:

;(
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);

最佳答案

我非常怀疑,因为您重写了整个原型(prototype),因此缺少构造函数。最好尝试单独分配原型(prototype)方法,例如

 Plugin.prototype._init  = function(){}

或者

再次设置构造函数

 Plugin.prototype.constructor  = Plugin;

关于javascript - 我的 jQuery 插件中定义的方法返回错误 : undefined is not a function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23711356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com