NodeIterator: phương thức detach()

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Phương thức NodeIterator.detach() không còn tác dụng gì, và chỉ được giữ lại để tương thích ngược.

Ban đầu, nó tách NodeIterator khỏi tập hợp mà nó duyệt, giải phóng mọi tài nguyên được tập hợp đó sử dụng và đặt trạng thái của bộ lặp thành INVALID. Sau khi phương thức này được gọi, việc gọi các phương thức khác trên NodeIterator sẽ gây ra ngoại lệ INVALID_STATE_ERR.

Cú pháp

js
detach()

Tham số

Không có.

Giá trị trả về

Không có (undefined).

Ví dụ

js
const nodeIterator = document.createNodeIterator(
  document.body,
  NodeFilter.SHOW_ELEMENT,
  {
    acceptNode(node) {
      return NodeFilter.FILTER_ACCEPT;
    },
  },
);
nodeIterator.detach(); // tách bộ lặp

nodeIterator.nextNode(); // ném ra ngoại lệ INVALID_STATE_ERR

Thông số kỹ thuật

Thông số kỹ thuật
DOM
# dom-nodeiterator-detach

Tương thích trình duyệt

Xem thêm