When using jQuery methods within an object function (ie – .each()), the “this” variable is then referencing the object being iterated over. How can I access the Object’s functions without “this”? I realize that’s a bit confusing, so:
test.prototype.init = function(node) {
node.children().each(function() {
//call test.anotherFunction() here
//Would normally call this.anotherFunction(),
// but "this" refers to the current child.
});
}
test.prototype.anotherFunction = function() {
//whatever
}
Help?
Save a copy of
thisinto a local variable (namedselfin this example, but you can name it anything you want) and use the saved copy in your embedded function: