过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

close() 方法在 WorkerGlobalScope interface discards any tasks queued in the WorkerGlobalScope 's event loop, effectively closing this particular scope.

句法

self.close();
					

范例

If you wanted to close your worker instance from inside the worker itself, you could call the following:

close();
					

close() and self.close() are effectively equivalent — both represent close() being called from inside the worker's inner scope.

注意 : there is also a way to stop the worker from the main thread: the Worker.terminate 方法。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
close 弃用 非标 Chrome 4 Edge 12 Firefox 3.5 IE Yes Opera 11.5 Safari 4 WebView Android 37 Chrome Android Yes Firefox Android 4 Opera Android ? Safari iOS ? Samsung Internet Android Yes
close() moved to DedicatedWorkerGlobalScope and SharedWorkerGlobalScope Chrome 52 Edge ≤79 Firefox 54 IE ? Opera ? Safari ? WebView Android 52 Chrome Android 52 Firefox Android 54 Opera Android ? Safari iOS ? Samsung Internet Android 6.0

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

另请参阅

WorkerGlobalScope

元数据

  • 最后修改: