0

Hi i am using object oriented javascript and using jquery animations . i am new in OOP Javascript. I am getting a error "TypeError: this.setUpAd is not a function" . I am trying to call a button event but getting this error.

init: function () {
        this.mainContainer = '#' + this.config.mainContainer;
        this.intro_image = '#' + this.config.intro_image;
        this.text1 = '#' + this.config.text1;
        this.text2 = '#' + this.config.text2;
        this.text3 = '#' + this.config.text3;


        $("#mainContainer").click(function () {
            this.setUpAd();
        });
    },


    bannerAnimation: function () {

        //Jquery Animation
        var text1 = this.text1;
        var text2 = this.text2;
        var text3 = this.text3;
        $(this.intro_image).animate({ width: "120px",
            height: "140px"
        }, 1000);
        $(text1).animate({ left: "20" }, 500, function () {
            $(text1).animate({ left: "10" }, 200);
            $("#btn2").animate({ left: "10" }, 200);
        });

        setTimeout(function () {
            $(text2).animate({ left: "20" }, 500, function () {
                $(text3).animate({ left: "20" }, 500, function () {
                    $(text3).animate({ left: "10" }, 200);
                });
                $(text2).animate({ left: "10" }, 200);
            });
        }, 1000);
    },
    // Handle Ad Setup



    setUpAd: function() {
  this.d("click").addEventListener('click', function (e) { EB.clickthrough(); }, false);

}

Or is there any better way to write the button click code. Thanks

Lasitha Benaragama
  • 2,201
  • 2
  • 27
  • 43

1 Answers1

0

In the context of your click-handler, this is not same as in your init() function.

You could assign the value to a variable and use that:

init: function () {
    var me = this;

    this.mainContainer = '#' + this.config.mainContainer;
    this.intro_image = '#' + this.config.intro_image;
    this.text1 = '#' + this.config.text1;
    this.text2 = '#' + this.config.text2;
    this.text3 = '#' + this.config.text3;

    $("#mainContainer").click(function () {
        me.setUpAd();
    });
},
jeroen
  • 91,079
  • 21
  • 114
  • 132