0

I've defined this.username already; however, when being inside a function it get undefined how can I retrieve its value?

 Parse.User.logIn(this.username, this.password, {
   success: function(user) {

       //gets undefined
       console.log('username is : ', this.username);

    }});
Folky.H
  • 1,114
  • 4
  • 14
  • 31

1 Answers1

1

it's because that callback has a different scope compared to the outer function.

save a reference of this outside the function

var self = this;

then use self inside the function.

Karim
  • 8,099
  • 2
  • 22
  • 32