Why does variable have same value for different instances?

Asked

Viewed 38 times

1

I have the following code

File 1 :

var fbuser_firstName;
var FB = require('fb');

var User = function (sender) {
    FB.api('/' + sender, 'get', {access_token: process.env.PAGE_ACCESS_TOKEN}, function (response) {
       User.initFbProfileInfo(response.first_name,response.locale);
     });
};

User.initFbProfileInfo = function (first_name,locale) {
   fbuser_firstName = first_name;
   fbuser_locale = locale;
};

User.prototype.getFb_firstName = function () {
    return fbuser_firstName;
};

module.exports = User;

File 2 :

for(//quantidade){
    user_profile = new User();
      user_profile.getFb_firstName(sender)
}

where Sender is a user identification. the fbuser_firstName variable should be named by the current user. The problem is that when you have 2 users at the same time, the 2 receive the same name. For example if the user speaks, the user will have the name of the userA as well. How can I resolve this? ( relates to the scope of the variable? )

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.