Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-10-04 14:11:36 +0300
committerNode.js GitHub Bot <github-bot@iojs.org>2020-10-11 17:35:17 +0300
commiteee522ac29864a55a8bc6686e6b38e93270aa1ca (patch)
tree3e7ac32cf16d758f1f7480fcb7ef47070c005391 /doc/api/events.md
parent705d888387f7a58c10711acbe5a4661c496969ad (diff)
lib: add EventTarget-related browser globals
Add - Event - EventTarget - MessagePort - MessageChannel - MessageEvent to the set of global objects, since they are available now and behave like they do in the browser. Fixes: https://github.com/nodejs/node/issues/35495 PR-URL: https://github.com/nodejs/node/pull/35496 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Khaidi Chu <i@2333.moe>
Diffstat (limited to 'doc/api/events.md')
-rw-r--r--doc/api/events.md21
1 files changed, 18 insertions, 3 deletions
diff --git a/doc/api/events.md b/doc/api/events.md
index 5de7e06840e..11e13e6d852 100644
--- a/doc/api/events.md
+++ b/doc/api/events.md
@@ -1069,9 +1069,15 @@ const ac = new AbortController();
process.nextTick(() => ac.abort());
```
+<a id="event-target-and-event-api"></a>
## `EventTarget` and `Event` API
<!-- YAML
added: v14.5.0
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/35496
+ description:
+ The `EventTarget` and `Event` classes are now available as globals.
-->
> Stability: 1 - Experimental
@@ -1082,7 +1088,7 @@ Neither the `EventTarget` nor `Event` classes are available for end
user code to create.
```js
-const target = getEventTargetSomehow();
+const target = new EventTarget();
target.addEventListener('foo', (event) => {
console.log('foo event happened!');
@@ -1168,7 +1174,7 @@ const handler4 = {
}
};
-const target = getEventTargetSomehow();
+const target = new EventTarget();
target.addEventListener('foo', handler1);
target.addEventListener('foo', handler2);
@@ -1189,6 +1195,10 @@ The `EventTarget` does not implement any special default handling for
### Class: `Event`
<!-- YAML
added: v14.5.0
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/35496
+ description: The `Event` class is now available through the global object.
-->
The `Event` object is an adaptation of the [`Event` Web API][]. Instances
@@ -1341,6 +1351,11 @@ The event type identifier.
### Class: `EventTarget`
<!-- YAML
added: v14.5.0
+changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/35496
+ description:
+ The `EventTarget` class is now available through the global object.
-->
#### `eventTarget.addEventListener(type, listener[, options])`
@@ -1374,7 +1389,7 @@ a `listener`. Any individual `listener` may be added once with
```js
function handler(event) {}
-const target = getEventTargetSomehow();
+const target = new EventTarget();
target.addEventListener('foo', handler, { capture: true }); // first
target.addEventListener('foo', handler, { capture: false }); // second