--- title: PeformanceObserver.disconnect() slug: Web/API/PerformanceObserver/disconnect translation_of: Web/API/PerformanceObserver/disconnect ---
{{domxref('PerformanceObserver')}} 接口的 disconnect()
方法用于阻止性能观察者接收任何 {{domxref("PerformanceEntry","性能条目", '', 'true')}} 事件。
performanceObserver.disconnect();
var observer = new PerformanceObserver(function(list, obj) { var entries = list.getEntries(); for (var i=0; i < entries.length; i++) { // Process "mark" and "frame" events } }); observer.observe({entryTypes: ["mark", "frame"]}); function perf_observer(list, observer) { // Process the "measure" event // ... // Disable additional performance events observer.disconnect(); } var observer2 = new PerformanceObserver(perf_observer); observer2.observe({entryTypes: ["measure"]});
Specification | Status | Comment |
---|---|---|
{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver-disconnect', 'disconnect()')}} | {{Spec2('Performance Timeline Level 2')}} | disconnect() 方法的初始定义。 |
{{Compat("api.PerformanceObserver.disconnect")}}