I ran into a weird problem at work last night where this one particular property of an object was undefined, but should have been a string.
What? Not that weird? Okay, fine.
But the weird part was that the object in question was getting created as the result of a call to JSON.parse(), and I knew that the JSON was totally valid. After a minute or two, it occurred to me that the value was probably getting set correctly when the object was intialized, but was then being overridden somehow elsewhere in the app.
So how do you find out where?
Here's the basic idea. We create a setter function on the object for the property name in question, and then just put in a debugger statement whenever the setter is called. That way, we can see the call stack in the console and figure out exactly where the assignment is happening.