I learned this the hard way, you have to be careful with this
. It always refers to the this
in the current scope, not it's containing object. Whenever you wrap something in function() { ... }
, this
becomes of a different scope. In your case, duplicate the object to a local variable and manipulate it's .data
property.
function File(data){
this.data = data;
var file = this; //call the variable whatever you want
this.update = function (callback){
var set = function(ajaxData){
file.data = ajaxData.PcbFile;
}
getPcbFile(data.id, function(ajaxData){
set(ajaxData);
callback();
});
};
}