Q:

setting back reference to parent in each tree node IE8 Out Of stack space

Continuied from json back reference.
I just want to travarse a hierarchy and set a property parent to its parent node. so that its both way travarsable
function attach_back_reference(hierarchy, parent){
        for(var i in hierarchy){
            if(jQuery.isPlainObject(hierarchy[i]))
                    attach_back_reference(hierarchy[i], hierarchy);
            else if(jQuery.isArray(hierarchy[i]))
                for(var it in hierarchy[i])
                        attach_back_reference(hierarchy[i][it], hierarchy);
        }
        hierarchy.parent = parent;
}

The above function works well in chrome, opera, firefox, IE9 . except IE 8 where it says Out of stack space. But I don't see anywhere it goes towards infinite recursion 

A:

Here's a version of your code which doesn't use recursion, so won't suffer from this:
function attach_back_reference( hierarchy, parent ) {
    var q = [{obj:hierarchy, p:parent}];
    while( q.length ) {
        var o = q.pop( ), x = o.obj;
        if( x.parent ) {
            continue;
        }
        for( var i in x ) {
            if( jQuery.isPlainObject( x[i] ) ) {
                q.push( {obj:x[i], p: x} );
            } else if( jQuery.isArray( x[i] ) ) {
                for( var j in x[i] ) {
                    q.push( {obj:x[i][j], p: x} );
                }
            }
        }
        o.p && (x.parent = o.p);
    }
}

(it also won't hang if given a graph with loops, but that's still not a good idea)

