EventCounts

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

EventCounts 介面是 Performance API 的一部分,用於提供每種事件型別已分派的事件數量。

EventCounts 例項是一個只讀的 Map 的物件,其中每個鍵是事件型別的名稱字串,對應的值是表示該事件型別已分派事件數量的整數。

建構函式

此介面沒有建構函式。您通常可以透過 performance.eventCounts 屬性獲取此物件的例項。

例項屬性

size

有關詳細資訊,請參閱 Map.prototype.size

例項方法

entries()

有關詳細資訊,請參閱 Map.prototype.entries()

forEach()

有關詳細資訊,請參閱 Map.prototype.forEach()

get()

有關詳細資訊,請參閱 Map.prototype.get()

has()

有關詳細資訊,請參閱 Map.prototype.has()

keys()

有關詳細資訊,請參閱 Map.prototype.keys()

values()

有關詳細資訊,請參閱 Map.prototype.values()

示例

使用 EventCount map

以下是一些從 EventCounts map 獲取資訊的示例。請注意,該 map 是隻讀的,並且沒有提供 clear()delete()set() 方法。

js
for (entry of performance.eventCounts.entries()) {
  const type = entry[0];
  const count = entry[1];
}

const clickCount = performance.eventCounts.get("click");

const isExposed = performance.eventCounts.has("mousemove");
const exposedEventsCount = performance.eventCounts.size;
const exposedEventsList = [...performance.eventCounts.keys()];

規範

規範
事件計時 API
# sec-event-counts

瀏覽器相容性

另見