AbstractWorker
接口在
Web 工作者 API
is an abstract interface that defines properties and methods that are common to all types of worker, including not only the basic
Worker
, but also
ServiceWorker
and
SharedWorker
.
As an abstract class, you don't directly interact with
AbstractWorker
.
AbstractWorker
interface doesn't inherit any properties.
AbstractWorker.onerror
EventListener
which is invoked whenever an
ErrorEvent
类型
error
bubbles through the worker.
AbstractWorker
interface doesn't implement or inherit any methods.
As an abstract interface, you won't directly use
AbstractWorker
in your code. Instead, you'll interact with either
Worker
or
SharedWorker
, both of which inherit the properties of
AbstractWorker
.
This code snippet demonstrates the creation of a new
Worker
使用
Worker()
constructor; it also shows how to then send a message to the worker.
var myWorker = new Worker('worker.js');
first.onchange = function() {
myWorker.postMessage([first.value, second.value]);
console.log('Message posted to worker');
}
The worker's code is loaded from the file
"worker.js"
. This code assumes that there's an
<input>
element represented by
第一
; an event handler for the
change
event is established so that when the user changes the value of
第一
, a message is posted to the worker to let it know.
You can find more examples on the MDN Web Docs GitHub repository:
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'AbstractWorker' in that specification. |
实时标准 | 无变化自 未知 . |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
AbstractWorker
|
Chrome 4 | Edge 12 | Firefox 3.5 | IE 10 | Opera 10.6 | Safari 4 | WebView Android 4.4 | Chrome Android 18 | Firefox Android 4 | Opera Android 11 | Safari iOS 5.1 | Samsung Internet Android 1.0 |
onerror
|
Chrome 4 | Edge 12 | Firefox 3.5 | IE 10 | Opera 10.6 | Safari 4 | WebView Android 4.4 | Chrome Android 18 | Firefox Android 4 | Opera Android 11 | Safari iOS 5.1 | Samsung Internet Android 1.0 |
完整支持
Worker
,
ServiceWorker
,和
SharedWorker
interfaces, which are all based upon
AbstractWorker
.