Javascript

React循环链表结构js实现

本文主要是介绍React循环链表结构js实现,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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);

  

这篇关于React循环链表结构js实现的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!