1

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(); and the error is 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().

Thanks.

1
  • 3
    this.CalculateQuantityAssigned Commented Jul 16, 2012 at 20:49

2 Answers 2

5

Change:

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

to

this.CalculateQuantityAssigned = function(){
            // ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Oh my god... Wow ! I forgot the this... Nice eye, this must be a sign of tiredness. Thanks a lot ! Will accept asap.
1
(function () {
});  <-- You have a function, but you never execute it!

You need to add the ();

1 Comment

You are right, })();. It is there, just my mitake that I didn't put in the "demo" script above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.