Skip to content

Commit

Permalink
Close some of the IE compatibility issues (#7)
Browse files Browse the repository at this point in the history
* es5 compatible

* upticked
  • Loading branch information
kevinatown authored Nov 6, 2023
1 parent af6b001 commit 1d7773a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if (shouldPolyfillEventTarget) {
) {
if (arguments.length < 2) {
throw new TypeError(
`TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`
"TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only " + arguments.length + " present."
);
}
const __listeners = this.__listeners;
Expand All @@ -71,7 +71,7 @@ if (shouldPolyfillEventTarget) {
) {
if (arguments.length < 2) {
throw new TypeError(
`TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`
"TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only " + arguments.length + " present."
);
}
const __listeners = this.__listeners;
Expand All @@ -87,14 +87,17 @@ if (shouldPolyfillEventTarget) {
EventTarget.prototype.dispatchEvent = function (event) {
if (!(event instanceof Event)) {
throw new TypeError(
`Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.`
"Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'."
);
}
const type = event.type;
const __listeners = this.__listeners;
const listenersForType = __listeners.get(type);
if (listenersForType) {
for (const [listener, options] of listenersForType.entries()) {
for (var listnerEntry of listenersForType.entries()) {
const listener = listnerEntry[0];
const options = listnerEntry[1];

try {
if (typeof listener === "function") {
// Listener functions must be executed with the EventTarget as the `this` context.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "event-target-polyfill",
"version": "0.0.3",
"version": "0.0.4",
"description": "An EventTarget Polyfill",
"main": "index.js",
"exports": {
Expand Down

0 comments on commit 1d7773a

Please sign in to comment.