Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

event-target-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-target-polyfill

An EventTarget Polyfill

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is event-target-polyfill?

The event-target-polyfill npm package provides a polyfill for the EventTarget interface, which is a standard interface implemented by objects that can receive events and may have listeners for them. This is particularly useful for environments that do not natively support EventTarget, such as older browsers or certain JavaScript environments.

What are event-target-polyfill's main functionalities?

Basic EventTarget Implementation

This code demonstrates the basic usage of the EventTarget polyfill. It shows how to create an EventTarget instance, add an event listener, dispatch an event, and remove the event listener.

const { EventTarget, Event } = require('event-target-polyfill');

const target = new EventTarget();

const listener = (event) => {
  console.log('Event received:', event.type);
};

target.addEventListener('test', listener);

target.dispatchEvent(new Event('test'));

target.removeEventListener('test', listener);

Custom Event Handling

This example shows how to create and dispatch a custom event with additional data using the EventTarget polyfill. It demonstrates extending the Event class to include custom properties.

const { EventTarget, Event } = require('event-target-polyfill');

class MyCustomEvent extends Event {
  constructor(type, customData) {
    super(type);
    this.customData = customData;
  }
}

const target = new EventTarget();

target.addEventListener('custom', (event) => {
  console.log('Custom event received with data:', event.customData);
});

target.dispatchEvent(new MyCustomEvent('custom', { key: 'value' }));

Other packages similar to event-target-polyfill

Keywords

FAQs

Package last updated on 06 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc