const queue = { pending: null }; function dispatchAction(action, queue) { const update = { action: action, next: null }; if (queue.pending == null) { update.next = update; } else { update.next = queue.pending.next; queue.pending.next = update; } queue.pending = update; } dispatchAction('update1', queue); dispatchAction('update2', queue); const first = queue.pending.next; let update = first; do { console.log(update); update = update.next; } while (update != first);