JSFiddle - React, Tailwind, and code Playground
JavaScript
var list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
function trampoline(f) {
while (f && f instanceof Function) {
f = f();
}
return f;
}
var nextListItem = function() {
var print = function(item) {
if (!item) {
// no more items, do nothing
return;
} else {
// log the item, or do some other processing
console.log(item);
// return another function to print the next value
return print.bind(null, list.pop());
}
}
return trampoline(print.bind(null, list.pop()));
};
nextListItem();