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,它所屬的介面。