MessageEvent: ports プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.
ports
は MessageEvent
インターフェイスの読み取り専用プロパティで、メッセージが(チャネルメッセージングや共有ワーカーにメッセージを送信する場合など、適切な場合に)送信されるチャネルに関連するポートを表す MessagePort
オブジェクトの配列です。
値
MessagePort
オブジェクトの配列です。
例
js
onconnect = (e) => {
const port = e.ports[0];
port.addEventListener("message", (e) => {
const workerResult = `Result: ${e.data[0] * e.data[1]}`;
port.postMessage(workerResult);
});
port.start(); // addEventListener を使用した場合は必要。 onmessage セッターからは暗黙に呼び出されます。
};
仕様書
Specification |
---|
HTML # dom-messageevent-ports-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ports |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on 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.
関連情報
ExtendableMessageEvent
— このインターフェイスに似ていますが、もっと柔軟性が必要なインターフェイスで使用されます。