I do not understand why this fails:
var recursiveElementGenerator = Function (elem_spec) {Elem = document.createElement (elem_spec.tag); If (elem_spec.children) {for (var i = 0; i & lt; elem_spec.children.length; i ++) {var c_elem = elem_spec.children [i]; Var n_elem = Recuritive element generator (c_elem); Warning (ELEM === n_elem); Elem.appendChild (n_elem); }; }; Return AMM; }; elem_spec objects have tags and properties of children, later there is an array of identical objects. This fails because the recursive call back by element is similar to the element created before the same recurring call. What I did not find - a similar version works, by getting a series of tag values from a pop () call on an array, then again it is passed in the recurring call.
Try using:
var elem = document CreateElement (elem_spec.tag); Instead of :
elem = document.createElement (elem_spec.tag); var is not using the keyword, your variable operates on the global scope. Using this will create the variable in the local area, which is built at the end of your function definition.
Comments
Post a Comment