WorkletSharedStorage: length() method

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 length() của giao diện WorkletSharedStorage trả về số lượng mục hiện đang được lưu trong bộ nhớ chia sẻ cho nguồn gốc hiện tại.

Cú pháp

js
length()

Tham số

Không có.

Giá trị trả về

Một Promise được thực hiện với số, đại diện cho tổng số cặp key-value hiện tại trong bộ nhớ chia sẻ.

Ngoại lệ

TypeError

Được ném ra nếu:

  • Module worklet chưa được thêm với addModule().
  • Trang gọi không có Shared Storage API trong privacy sandbox enrollment process thành công.
  • Trình duyệt không thể lấy số lượng mục vì một lý do khác.

Ví dụ

js
// length() available inside a shared storage worklet module

async function retrieveLength() {
  const length = await this.sharedStorage.length();
  console.log(length);
}

Thông số kỹ thuật

Tính năng này dường như chưa được định nghĩa trong bất kỳ thông số kỹ thuật nào.

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

Xem thêm