Code Monkey home page Code Monkey logo

node_custom-event-emitter's Introduction

Custom Event Emitter (Node.js)

Create a custom MyEventEmitter class that mimics the behavior of Node.js EventEmitter. Implement the following methods:

  1. on: Adds a listener to the end of the listeners array for the specified event.
  2. once: Adds a one-time listener for the event. The listener is invoked only the next time the event is fired, after which it is removed.
  3. off: Removes the specified listener from the listener array for the specified event.
  4. emit: Synchronously calls each of the listeners registered for the event, in the order they were registered, passing the supplied arguments to each.
  5. prependListener: Adds a listener to the beginning of the listeners array for the specified event.
  6. prependOnceListener: Adds a one-time listener for the event to the beginning of the listeners array. The listener is invoked only the next time the event is fired, after which it is removed.
  7. removeAllListeners: Remove all listeners for a specific event, or all events if no event is specified.
  8. listenerCount: Returns the number of listeners for a given event.

Instructions

  • Follow the JavaScript task guideline before starting.
  • Implement a solution by creating a class MyEventEmitter that includes the required methods.
  • Make sure to handle edge cases, such as removing a non-existent listener or emitting an event with no listeners registered.
  • Test your implementation with various scenarios to ensure correctness.

Note: This task does not require any external libraries or modules. You should implement the EventEmitter from scratch using only built-in JavaScript features.

node_custom-event-emitter's People

Contributors

andr1yk avatar mgrinko avatar sergii-nosachenko avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.