1

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?

blueFast
  • 41,341
  • 63
  • 198
  • 344
  • This is using Prototype, right? I don't get it; you're setting "tmp" to a DOM element, no? Why would it be an Object? (Oh wait; it's a couchdb thing. Never mind.) – Pointy Nov 03 '11 at 13:08
  • 3
    undefined is not a reserved word and can be set to something else (leading to bugs). The != operator coerces its arguments, you should almost always use === and !== instead. – hugomg Nov 03 '11 at 13:08

0 Answers0