[英]Javascript error - Object has no method
I got the following script shortened : 我缩短了以下脚本:
var HTH = HTH || {};
(function() {
var assetGrouping = function() {
var self = this;
this.options = {
_tmpElement: '',
QuantityAssigned: 0,
qtyInputField: ''
};
this.init = function(options){
// ...
this.options.QuantityAssigned = 0;
jQuery(this.options.qtyInputField).bind('keyup', function(){
self._tmpElement = jQuery(this);
self.CalculateQuantityAssigned();
});
// ...
}
CalculateQuantityAssigned = function(){
// ...
}
}
HTH.assetGrouping = new assetGrouping();
})();
$(document).ready(function(){
HTH.assetGrouping.init({
qtyInputField: 'input[name^="at700_group_qty"]'
});
});
The error happen at the following line : self.CalculateQuantityAssigned();
错误发生在以下行:
self.CalculateQuantityAssigned();
and the error is Uncaught TypeError: Object [object Object] has no method 'CalculateQuantityAssigned'
. 并且错误是
Uncaught TypeError: Object [object Object] has no method 'CalculateQuantityAssigned'
。
I don't understand. 我不明白 Using
this
will fail of course and self
is working when I want to access self.options
but not for self.CalculateQuantityAssigned()
. 使用
this
方法当然会失败,并且当我要访问self.options
而不是self.CalculateQuantityAssigned()
时, self
可以正常工作。
Thanks. 谢谢。
Change: 更改:
CalculateQuantityAssigned = function(){
// ...
}
to 至
this.CalculateQuantityAssigned = function(){
// ...
}
(function () {
}); <-- You have a function, but you never execute it!
You need to add the ();
您需要添加
();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.