Web Workers API
The port property of the SharedWorker
interface returns a MessagePort object used to communicate and control
the shared worker.
Value
A MessagePort object.
Examples
The following code snippet shows creation of a SharedWorker object using
the SharedWorker.SharedWorker constructor. Multiple
scripts can then access the worker through a MessagePort object accessed
using the SharedWorker.port property — the port is started using its
start() method:
const myWorker = new SharedWorker("worker.js");
myWorker.port.start();
For a full example, see our Basic shared worker example (run shared worker.)
Specifications
Browser compatibility
See also
- SharedWorker
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
