Skip to Content
JavaScript: The Definitive Guide, 6th Edition
book

JavaScript: The Definitive Guide, 6th Edition

by David Flanagan
May 2011
Intermediate to advanced
1093 pages
40h 54m
English
O'Reilly Media, Inc.
Content preview from JavaScript: The Definitive Guide, 6th Edition

Name

MessageChannel — a pair of connected MessagePorts

Synopsis

A MessageChannel is simply a pair of connected MessagePort objects. Calling post Message() on either one triggers a message event on the other. If you want to establish a private communication channel with a Window or Worker thread, create a MessageChannel and then pass one member of the MessagePort pair to the Window or Worker (using the ports argument of postMessage()).

MessageChannel and MessagePort types are an advanced feature of HTML5 and, at the time of this writing, some browsers support cross-origin messaging (Cross-Origin Messaging) and worker threads (Web Workers) without supporting private communication channels with MessagePort.

Constructor

new MessageChannel()

This no-argument constructor returns a new MessageChannel object.

Properties

readonly MessagePort port1readonly MessagePort port2

These are the two connected ports that define the communication channel. The two are symmetrical: retain one or the other for your code, and pass the other to the Window or Worker you want to communicate with.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaScript: The Definitive Guide, 5th Edition

JavaScript: The Definitive Guide, 5th Edition

David Flanagan

Publisher Resources

ISBN: 9781449393854Errata PageSupplemental Content