i've used prototype before, and i'm trying to learn jquery now. The problem: I have an object that makes an ajax call, and i want the success callback to call a function within my object. The problem is that inside the callback function, "this" does not point to my original class.
Example:
function C(){
this.loadData();
}
C.prototype.loadData = function(){
$.ajax({
url:"URL/",
dataType:'json',
success:this.dataRetreived
});
}
C.prototype.dataRetreived = function(JSON){
console.info(this);
console.info(JSON);
}
Using Prototype i'd could simply use .bind(this), but jquery has a different way of doing things..
function.bindas in Prototype is a standard part of ECMAScript Fifth Edition so you'll be able to use it anyway in the future without having to hack the function prototype.Function.prototypemyself, as I don't use Prototype). Between this, the Strict Mode fixes, and the addition of long-standard Mozilla features to the language, JavaScript is finally getting a bit less horrible.