0

I declare user_properties outside of my function. I then get my data from firebase and try to store it in user_properties but it ends up being undefined.

Does anyone know what I am doing wrong here?

var user_properties;

get_user_properties = new Firebase("https://<MY-URL>/users/"+auth.uid+"/properties");
get_user_properties.once('value', function (dataSnapshot) {
  user_properties = dataSnapshot.val();
});

//undefined
console.log(user_properties);
bryan
  • 8,879
  • 18
  • 83
  • 166

1 Answers1

0

I've provided for you a simple example.

var foo,
    obj = new Bar("some text");

obj.set("cute cat", function(cat){
    foo = "my lovely cat";
});

console.log(foo); // undefined
obj.doo();
console.log(foo); // "my lovely cat"

With this constructor function

function Bar(c){
    this.mcat = c;
    this.callback;

    /* this method only saves that callback function */
    this.set = function(catname, callback){
        this.mcat = catname;
        this.callback = callback;
    }

    /* this method calls that callback function */
    this.doo = function(){
        this.callback();
    }
}
frogatto
  • 28,539
  • 11
  • 83
  • 129