DedicatedWorkerGlobalScope

DedicatedWorkerGlobalScope object (the Worker 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 also: Functions available to workers .

特性

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

DedicatedWorkerGlobalScope.name 只读
The name that the Worker was (optionally) given when it was created using the Worker() constructor. This is mainly useful for debugging purposes.

Properties inherited from WorkerGlobalScope

WorkerGlobalScope.self
Returns an object reference to the DedicatedWorkerGlobalScope object itself.
WorkerGlobalScope.console 只读
返回 Console associated with the worker.
WorkerGlobalScope.location 只读
返回 WorkerLocation associated with the worker. WorkerLocation is a specific location object, mostly a subset of the Location 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 只读
返回 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 .

DedicatedWorkerGlobalScope.onmessage
Is an EventHandler representing the code to be called when the message event is raised. These events are of type MessageEvent and will be called when the worker receives a message from the document that started it (i.e. from the Worker.postMessage method.)
DedicatedWorkerGlobalScope.onmessageerror
Is an EventHandler representing the code to be called when the messageerror event is raised.

方法

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

DedicatedWorkerGlobalScope.close()
Discards any tasks queued in the WorkerGlobalScope 's event loop, effectively closing this particular scope.
DedicatedWorkerGlobalScope.postMessage()
Sends a message — which can consist of any JavaScript object — to the parent document that first spawned the worker.

Inherited from WorkerGlobalScope

WorkerGlobalScope.dump()
Writes a message to the console.
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.

Events

message
Fired when the worker receives a message from its parent.
Also available via the onmessage 特性。
messageerror
Fired when a worker receives a message that can't be deserialized.
Also available via the onmessageerror 特性。

规范

规范 状态 Comment
HTML Living Standard
The definition of 'DedicatedWorkerGlobalScope' in that specification.
实时标准

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
DedicatedWorkerGlobalScope Chrome 4 Edge 12 Firefox 3.5 IE 10 Opera 10.6 Safari 4 WebView Android Yes Chrome Android 18 Firefox Android 4 Opera Android 11 Safari iOS 5.1 Samsung Internet Android 1.0
close Chrome Yes Edge ≤79 Firefox 54 IE ? Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android 54 Opera Android Yes Safari iOS ? Samsung Internet Android Yes
message event Chrome 4 Edge 12 Firefox 3.5 IE 10 Opera 10.6 Safari 4 WebView Android 37 Chrome Android Yes Firefox Android 4 Opera Android 11.5 Safari iOS 5.1 Samsung Internet Android Yes
messageerror event Chrome 60 Edge ≤79 Firefox 57 IE ? Opera 47 Safari ? WebView Android 60 Chrome Android 60 Firefox Android 57 Opera Android 47 Safari iOS ? Samsung Internet Android 8.0
name Chrome Yes Edge ≤79 Firefox 55 IE 不支持 No Opera ? Safari 不支持 No WebView Android Yes Chrome Android Yes Firefox Android 55 Opera Android ? Safari iOS 不支持 No Samsung Internet Android Yes
onmessage Chrome 4 Edge 12 Firefox 3.5 IE 10 Opera 10.6 Safari 4 WebView Android 37 Chrome Android Yes Firefox Android 4 Opera Android 11 Safari iOS 5.1 Samsung Internet Android Yes
onmessageerror Chrome 60 Edge ≤79 Firefox 57 IE ? Opera 47 Safari ? WebView Android 60 Chrome Android 60 Firefox Android 57 Opera Android 44 Safari iOS ? Samsung Internet Android 8.0
postMessage Chrome 4 Edge 12 Firefox 3.5 IE 10 Opera 10.6 Safari 4 WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android 11 Safari iOS 5.1 Samsung Internet Android Yes

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知

另请参阅