BroadcastChannel:close() 方法
注意:此功能在 Web Workers 中可用。
close() 方法是 BroadcastChannel 接口的一个方法,用于终止与底层通道的连接,从而允许该对象被垃圾回收。这是一个必要的步骤,因为浏览器没有其他方法知道不再需要这个通道。
语法
js
close()
参数
无。
返回值
无(undefined)。
示例
js
// Connect to a channel
const bc = new BroadcastChannel("test_channel");
// More operations (like postMessage, …)
// When done, disconnect from the channel
bc.close();
规范
| 规范 |
|---|
| HTML # dom-broadcastchannel-close-dev |
浏览器兼容性
加载中…
另见
BroadcastChannel,它所属的接口。