Problems accessing object member in javascript

82 Views Asked by At

In a _changes/data.js file I have the following implementation:

function(data) {
    var p;
    var tmp = $$("#profile");
    $.log(tmp);
    $.log(tmp.profile);
    if (undefined != tmp.profile) {
        return {
            cdrs : data.rows.map(function(r) {
                p = r.value;
                return p;
            }),
            message : "You are logged in as " + tmp.profile.name,
        }
    } else {
        return {
            cdrs : [ ] ,
            message : "You are not logged in",
        }
    }
};

I am confused because, right after reloading the aplication, $.log(tmp.profile); is showing "undefined", even though the previous $.log(tmp); is clearly showing that the javascript object has indeed a member named profile (of type Object, with the expected data).

It is even stranger: when the change notification kicks in, $.log(tmp.profile); is showing the right data, even though $.log(tmp); does not show any change.

What is going on? Am I missing any encapsulation rules here?

0

There are 0 best solutions below