https://learn.javascript.ru/task/output-single-linked-list

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
"use strict";
var printListM = function(obj) {
while (obj.next) {
obj = obj.next;
}
alert(obj.value);
};
var printListR = function(obj) {
alert(obj.value);
if (obj.next != undefined) {
printListR(obj.next);
}
};
var list = {value: 1};
list.next = {value: 2};
list.next.next = {value: 3};
list.next.next.next = {value: 4};
printListR(list);