Before reading on, realize that I already know the fix to my problem. But don't understand why it works and I could really use some clarification.
So I'm trying to create an object as soon as the user authenticates. So I can associate methods with that object (ex: delete the users node when the the browser is closed) but encountered a very weird issue.
First of all, as soon as the user authenticates I create a new object like so
user = new handleData(authData.uid, authData.google.displayName, authData.google.profileImageURL);
my handleData constructor looks a bit like this
function handleData(){
this.uid = arguments[0];
this.name = arguments[1];
this.profilePicture = arguments[2];
var userNode = "users/{0}".format(this.uid);
var data = {
name : this.name,
profilePicture : this.profilePicture
}
//Doesnt work code
myDatabase.child(userNode).set({
name: this.name,
profilePicture : this.profilePicture
});
//Works
myDatabase.child(userNode).set(data);
};
Firebase throws this error when I try the first child .set({})
Script:455 is the first line after the //Doesnt work comment in my snippet. If I just set an object (data) then my code just works without issues which is weird because they are identically the same.
Also I want to mention that, if I just call my functions without the new operator, the code just works. So what is the new operator doing that breaks my code?