Performance: clearMeasures() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
Note: This feature is available in Web Workers.
Phương thức clearMeasures() xóa tất cả hoặc các đối tượng PerformanceMeasure cụ thể khỏi timeline hiệu năng của trình duyệt.
Cú pháp
js
clearMeasures()
clearMeasures(name)
Tham số
nameOptional-
Một chuỗi biểu thị
namecủa đối tượngPerformanceMeasure. Nếu bỏ qua đối số này, tất cả các entry cóentryTypelà"measure"sẽ bị xóa.
Giá trị trả về
Không có (undefined).
Ví dụ
>Xóa các measure
Để dọn sạch tất cả performance measure, hoặc chỉ các entry cụ thể, hãy dùng phương thức clearMeasures() như sau:
js
// Tạo một loạt measure
performance.measure("from navigation");
performance.mark("a");
performance.measure("from mark a", "a");
performance.measure("from navigation");
performance.measure("from mark a", "a");
performance.mark("b");
performance.measure("between a and b", "a", "b");
performance.getEntriesByType("measure").length; // 5
// Chỉ xóa các entry measure "from navigation"
performance.clearMeasures("from navigation");
performance.getEntriesByType("measure").length; // 3
// Xóa tất cả entry measure
performance.clearMeasures();
performance.getEntriesByType("measure").length; // 0
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| User Timing> # dom-performance-clearmeasures> |