1

我缩短了以下脚本:

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"]'
    });
});

错误发生在以下行:self.CalculateQuantityAssigned();并且错误是Uncaught TypeError: Object [object Object] has no method 'CalculateQuantityAssigned'

我不明白。使用this当然会失败,并且self当我想访问self.options但不用于self.CalculateQuantityAssigned().

谢谢。

4

2 回答 2

5

改变:

CalculateQuantityAssigned = function(){
            // ...
}

this.CalculateQuantityAssigned = function(){
            // ...
}
于 2012-07-16T20:49:47.130 回答
1
(function () {
});  <-- You have a function, but you never execute it!

您需要添加();

于 2012-07-16T20:57:13.820 回答