Is there any way to pass context in javascript facebook sdk api callback? Here is a simple example. Now this will not work, because the variable 'this.name' in my callback function will be undefined, because it is not in my context of custom objects. Any idea how to do this?
function user(id) {
this.id = id;
this.getUserName = function(fields,callback){
FB.api({
method:'fql.query',
query: 'SELECT '+ fields.toString() +' FROM profile WHERE id=' + this.id
},
callback
);
}
this.getUserName(['name'],function(response){this.name = response[0].name;});
}
var amigo = new user('fb_id_here');
source
share