SharedWorkerGlobalScope object (the SharedWorker global scope) is accessible through the self keyword. Some additional global functions, namespaces objects, and constructors, not typically associated with the worker global scope, but available on it, are listed in the JavaScript 参考 . See the complete list of functions available to workers .

特性

此接口继承的特性来自 WorkerGlobalScope interface, and its parent EventTarget , and therefore implements properties from WindowTimers , WindowBase64 ,和 WindowEventHandlers .

SharedWorkerGlobalScope.name 只读
The name that the SharedWorker was (optionally) given when it was created using the SharedWorker() constructor. This is mainly useful for debugging purposes.
SharedWorkerGlobalScope.applicationCache 只读
This property returns the ApplicationCache object for the worker (see Using the application cache ).

Properties inherited from WorkerGlobalScope

WorkerGlobalScope.self
Returns an object reference to the DedicatedWorkerGlobalScope 对象自身。
WorkerGlobalScope.console 只读
返回 控制台 associated with the worker.
WorkerGlobalScope.location 只读
返回 WorkerLocation associated with the worker. WorkerLocation is a specific location object, mostly a subset of the 定位 for browsing scopes, but adapted to workers.
WorkerGlobalScope.navigator 只读
返回 WorkerNavigator associated with the worker. WorkerNavigator is a specific navigator object, mostly a subset of the Navigator for browsing scopes, but adapted to workers.
WorkerGlobalScope.performance 只读
返回 性能 object associated with the worker, which is a regular performance object, but with a subset of its properties and methods available.

事件处理程序

This interface inherits event handlers from the WorkerGlobalScope interface, and its parent EventTarget , and therefore implements event handlers from WindowTimers , WindowBase64 ,和 WindowEventHandlers .

SharedWorkerGlobalScope.onconnect
EventHandler 表示要调用的代码当 connect event is raised — that is, when a MessagePort connection is opened between the associated SharedWorker and the main thread.

方法

此接口继承的方法来自 WorkerGlobalScope interface, and its parent EventTarget , and therefore implements methods from WindowTimers , WindowBase64 ,和 WindowEventHandlers .

SharedWorkerGlobalScope.close()
Discards any tasks queued in the SharedWorkerGlobalScope 's event loop, effectively closing this particular scope.

Inherited from WorkerGlobalScope

WorkerGlobalScope.close()
Discards any tasks queued in the WorkerGlobalScope 's event loop, effectively closing this particular scope.
WorkerGlobalScope.dump()
Allows you to write a message to stdout — i.e. in your terminal. This is the same as Firefox's window.dump , but for workers.
WorkerGlobalScope.importScripts()
Imports one or more scripts into the worker's scope. You can specify as many as you'd like, separated by commas. For example: importScripts('foo.js', 'bar.js');

Implemented from other places

WindowBase64.atob()

Decodes a string of data which has been encoded using base-64 encoding.

WindowBase64.btoa()

Creates a base-64 encoded ASCII string from a string of binary data.

WindowTimers.clearInterval()
Cancels the repeated execution set using WindowTimers.setInterval() .
WindowTimers.clearTimeout()
Cancels the repeated execution set using WindowTimers.setTimeout() .
WindowTimers.setInterval()

Schedules the execution of a function every X milliseconds.

WindowTimers.setTimeout()

Sets a delay for executing a function.

事件

Listen to this event using addEventListener() 或通过把事件监听器赋值给 on eventname 特性为此接口。

connect
Fired on shared workers when a new client connects.
也可用凭借 onconnect 特性。

规范

规范 状态 注释
HTML 实时标准
The definition of 'SharedWorkerGlobalScope' in that specification.
实时标准

浏览器兼容性

The compatibility table in 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
SharedWorkerGlobalScope Chrome 4 Edge ≤79 Firefox 29 IE No Opera 10.6 Safari 5 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android 11 Safari iOS 7 Samsung Internet Android Yes
applicationCache Chrome 4 Edge ≤79 Firefox 29 IE No Opera 10.6 Safari No WebView Android Yes Chrome Android Yes Firefox Android 29 Opera Android Yes Safari iOS ? Samsung Internet Android Yes
close Chrome No Edge No Firefox 54 IE No Opera No Safari ? WebView Android No Chrome Android No Firefox Android 54 Opera Android No Safari iOS ? Samsung Internet Android No
connect event Chrome 4 Edge ≤79 Firefox 29
29
Before version 65 the data property of the event object was null ; it is now initialized to an empty string, as per spec.
IE No Opera 10.6 Safari No WebView Android Yes Chrome Android 18 Firefox Android 29
29
Before version 65 the data property of the event object was null ; it is now initialized to an empty string, as per spec.
Opera Android Yes Safari iOS ? Samsung Internet Android 1.0
名称 Chrome Yes Edge ≤79 Firefox 55 IE No Opera 10.6 Safari No WebView Android Yes Chrome Android 40 Firefox Android 55 Opera Android Yes Safari iOS No Samsung Internet Android 4.0
onconnect Chrome 4 Edge ≤79 Firefox 29 IE No Opera 10.6 Safari No WebView Android Yes Chrome Android 18 Firefox Android 29 Opera Android Yes Safari iOS ? Samsung Internet Android 1.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

另请参阅

元数据

  • 最后修改: