I have an object with a function called 'getHtml(elem)' and I want to access it while $.each iterates over an array. I understand that 'this' refers to the element in the $.each iteration, so how does one access an object's functions?
Ex:
MyObject.prototype.doSomething = function() {
var results = this.getElements(); //returns this object's array of objects
var html;
var elems = [];
var elem;
$.each(results, function(index, value) {
elem = $(this); //refers to the object returned in the $.each function
html = this.getHtml(elem); //doesn't work, this doesn't refer to this object
elems.push(html);
});
},
the error I get is: Uncaught TypeError: this.getHtml is not a function
I tried to read up on bind(), but I don't understand how to use it. How does one call an object's function within an $.each?