定义的方法在我的jQuery插件返回's错误:未定义的不是一个函数
Defined method in my jQuery plugin return's the error : undefined is not a function?
我有以下代码,并且我得到错误Uncaught TypeError: undefined is not a function (repeated 8 times)
的方法_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;
相关文章:
- Jquery未定义函数正在停止其他操作
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- Uncaught ReferenceError:尝试在Android网络视图中访问时未定义函数
- jQuery文件上传和验证未定义函数
- 引用错误:未定义函数-Firefox
- res.render中出错,未定义函数
- 神秘的未定义函数
- 尝试使用函数和Ajax修改值时未定义函数
- 引用错误:未定义函数
- ReferenceError:未定义函数
- 在 Angular JS 中使用 ng-include 的未定义函数
- 未捕获的引用错误:未定义函数
- j查询工具提示引发错误:未定义函数
- 未捕获的引用错误: 未定义单击世界 -- 未定义函数
- JS:引用错误:未定义函数
- 茉莉花未定义函数
- Javascript 错误:未捕获的引用错误:未定义 [函数]
- 未定义函数
- 尽管 js 文件引用在标头中,但未定义函数
- Javascript 未定义函数错误