AbstractWorker

AbstractWorker interface of the 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
An EventListener which is invoked whenever an ErrorEvent of type 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 first ; an event handler for the change event is established so that when the user changes the value of first , a message is posted to the worker to let it know.

You can find more examples on the MDN Web Docs GitHub repository:

规范

规范 状态 Comment
HTML Living Standard
The definition of 'AbstractWorker' in that specification.
实时标准 No change from 未知 .

浏览器兼容性

更新 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
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

图例

完整支持
完整支持

另请参阅