Кривой костыль
<script>
var list = {
value: 1,
next: {
value: 2,
next: {
value: 3,
next: {
value: 4,
next: null
}
}
}
};
var vName = "list",
down = true;
function printList(lst) {
console.log(lst.value);
if (lst.next && down) {
vName += ".next";
printList(lst.next);
}
else {
down = false;
if(vName.length > 5) {
vName = vName.substr(0,vName.length - 5);
printList(eval(vName));
}
}
}
printList(list);
</script>