其他分享
首页 > 其他分享> > 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,null,const,update,queue,next,链表,js,pending
来源: https://www.cnblogs.com/dming4/p/15491813.html