Javascript objects & methods: what can see what, and why? -
i've got set that, in stylised form, this:
(function () { var db = { com: { edit: changed [...] {...} 324: { unmod: "xyz" } } }; var report = { mymethod: function () { var x = db.com[324].unmod; } }; })();
the error message i'm getting db.com undefined
. seems me report.mymethod
cannot "see" db.com
. right?
one factor might db.com
created looping through ajax data this:
(i = 0; < length1; i++) { cat = o.cat[i]; length2 = cat.com.length; // loop through comments (j = 0; j < length2; j++) { com = cat.com[j]; // create db object this[com.cnum] = { unmod: com.unmod }; } }
is issue 1 of closure?
the relevant part of ajax data this
"cat":[ { ... "com": [ {"cnum":"324", "unmod":"xyz"},...] }, ...],
apologies ajax names , property names same. makes easier me, perhaps not y'all :)
example code works expected after fixing population part: http://jsfiddle.net/4bl8t/
Comments
Post a Comment