Try this:
function File(data){
this.data = data;
var self = this;
this.update = function (callback){
var set = function(ajaxData){
self.data = ajaxData.PcbFile;
}
getPcbFile(data.id, function(ajaxData){
set(ajaxData);
callback();
});
};
}
The value of this
within a function depends on how that function is called. E.g., when you use the "dot" notation, someObj.someMethod()
then within someMethod()
you'd have this
set to someObj
. You can explicitly set this
to some other object using the .apply()
or .call()
methods. Otherwise if you call a function as with set(ajaxData)
then this
will be the global object (window
).
By keeping a reference to this
outside your function (I prefer the variable name self
for this purpose) you can reference it inside your function.