3 JavaScript Lessons: Hoisting, console.log and deep object copy
Whew! several days of debugging later, i found not one but three magic bullets to my problem.
1. Beware of Javscript Hoisting!!!! Always, always, always var scope your function-specific variables at the top of your javascript function. Lest you find debugging a nightmare because hoisting will initially declare your variables as undefined via its hoisting “feature”. http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting
2. Lesson number 2: console.log only shows final state of an object, not “current” state. Use console.dir instead. http://stackoverflow.com/questions/7389069/console-log-object-at-current-state
3. Final lesson!!! jquery clone() has an option to do a deep copy rather than a shallow copy objects! http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object
so my problem wasn’t one thing, but three things all confusing the $#!@@#$ out of me. Hope this posts saves you some of the same pain.