Javascript internal call when using jquery

I have a little problem with an object that uses jquery. since jquery overwrites this pointer, which I cannot call my helper methods without resorting to storing this pointer in this variable, is this the preferred way or is there a better solution? Is there a way to store this pointer in an object (for example, a class method with a different name)?

Trying to learn javascript with javascript in good parts, but I don't think I understand all the quirks :).

//from javscript the good parts
if (typeof Object.create !== 'function') {
    Object.create = function (o) {
        var F = function () {};
        F.prototype = o;
        return new F();
    };
}

var Tester = {
    printData: function (text) {
        console.log(text)
    },
    start: function () {
        var that = this;
        jQuery('id').click(function () {
             that.printData('firstColumn')
    });
  }
};

var test = Object.create(Tester)

test.start()

Best regards Anders Olme, suppose this looks like a reserved problem with the variable "his" or how to call a member function?

+5
1

, , , .

jQuery .

jQuery('id')   // <-- should be #id ?
    .bind('click', { myThing : this }, function (e) {
        e.data.myThing.printData('firstColumn');
    })
;

docs bind(). jQuery , , , .

+1

All Articles