I'm building a backbone.js app with facebook api and phonegap.
In my User model, I'm trying to attach a listener to see when the user has logged in.
Myapp.Models.User = Backbone.Model.extend({
initialize: function(){
FB.Event.subscribe('auth.login', function(response){
console.log('logged-in event');
this.get_me();
});
},
get_me: function(){
console.log('use the api to get user details');
}
});
of course, when I do this, the this is (I believe) attached to FB, not Myapp.
I've tried
var this_user = this;
FB.Event.subscribe('auth.login', function(response,this_user){
this_user.get_user();
}
but that still fails.
I've read all sorts of blogs on how to use this, but can't seem to get one that I actually understand when working with multiple objects and how do I refer back to the original object.