JavaScripture
Contribute via GitHub Feedback

MessagePort : EventTarget

Represents one side of a MessageChannel that can send messages to and receive messages from the other MessagePort of the MessageChannel. MessagePorts can be transferred to other contexts by passing it in the transfer parameter of MessagePort.postMessage() or Window.postMessage().

Instance Methods

close() : undefined

postMessage(message : Object, [transfer : Array<Transferable>]) : undefined

Serializes message and sends it to the other MessagePort.

Example:

Run

Results:

 

start() : undefined

Starts listening to messages. This is automatically called if you set the onmessage event listener.

Instance Events

onmessage / 'message'  
listener(event : MessageEvent) : undefined

Fired when postMessage is called on the other port of the MessageChannel. Setting onmessage will automatically call start(). When using addEventListener('message'), you must call start() to begin receiving message events.