javascript - Node iterator failing when being used to instantiate objects -
i'm using javascript node iterator create instances of object attached elements within dom. following code i'm using , works fine:
var nodeiterator = document.createnodeiterator( document.body, nodefilter.show_element, { acceptnode: function(node) { if (node.attributes['data-sd-autocomplete'] && node.type === 'text') return nodefilter.filter_accept; } }, false ), nodelist = [], node; sdautocomplete.fields = []; while (node = nodeiterator.nextnode()) nodelist.push(node); // add new instances of sdautocomplete fields list (var = 0; < nodelist.length; i++) { sdautocomplete.fields.push(new sdautocomplete(nodelist[i])); }
i tried shorten code make more concise, removing loop , replacing line within while loop directly instantiates node variable:
while (node = nodeiterator.nextnode()) sdautocomplete.fields.push(new sdautocomplete(node));
but causes page hang if while loop getting stuck. shed light on why case?
Comments
Post a Comment