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

浏览器兼容性

另见