0

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({})

firebase set error

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?

realappie
  • 4,656
  • 2
  • 29
  • 38
  • 2
    Those two things you posted are exactly equivalent. The error you've got suggests that you're actually doing something like `{[this.profilePicture]: undefined}` – Bergi Feb 09 '16 at 11:34
  • But I am obviously not doing that ? Its really confusing – realappie Feb 09 '16 at 16:42
  • Are you sure the `set` call is not inside of some callback? Is this your complete and exact code? – Bergi Feb 09 '16 at 16:46
  • My set is in two callbacks, but console logging ""this.name" & "this.profilePicture" gives me the appropriate values. Do you this this is just a pointer issue ? Also if you want complete and exact code checkout this [jsfiddle](https://jsfiddle.net/087a19th/) Problem occurs at line 47 – realappie Feb 09 '16 at 20:57
  • No, logging `this.name` in that location won't give you the appropriate values either. – Bergi Feb 10 '16 at 11:49
  • @bergi I think the pointers are just pointing to someone else. Instead of using pointers all over my function. I decided to assign them to a local variable at the start of my function so that I can properly refer to them later on. – realappie Feb 10 '16 at 11:54

0 Answers0