Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:40:20+00:00 2026-05-23T16:40:20+00:00

I just found out that FileReader dispatches events just as if it was a

  • 0

I just found out that FileReader dispatches events just as if it was a DOM element. Is it? I wonder if it’s possible to create an object similar to FileReader, which doesn’t have a representation in HTML/XML structure, but can dispatch events?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:40:20+00:00Added an answer on May 23, 2026 at 4:40 pm

    FileReader has methods like addEventHandler because it is defined to implement the EventTarget interface. EventTarget is defined by the DOM Events spec but you don’t need to be a DOM object to implement it. window, XMLHttpRequest and FileReader are other Browser Object Model objects that implement EventTarget.

    Unfortunately there’s no easy way to piggyback on the browser’s native implementation of event targets… you could try inheriting from a browser object by using one as a prototype property, but that’s very unreliable in general. However it is not too difficult to write code to implement all the methods yourself in plain JavaScript:

    function CustomEventTarget() { this._init(); }
    
    CustomEventTarget.prototype._init= function() {
        this._registrations= {};
    };
    CustomEventTarget.prototype._getListeners= function(type, useCapture) {
        var captype= (useCapture? '1' : '0')+type;
        if (!(captype in this._registrations))
            this._registrations[captype]= [];
        return this._registrations[captype];
    };
    
    CustomEventTarget.prototype.addEventListener= function(type, listener, useCapture) {
        var listeners= this._getListeners(type, useCapture);
        var ix= listeners.indexOf(listener);
        if (ix===-1)
            listeners.push(listener);
    };
    
    CustomEventTarget.prototype.removeEventListener= function(type, listener, useCapture) {
        var listeners= this._getListeners(type, useCapture);
        var ix= listeners.indexOf(listener);
        if (ix!==-1)
            listeners.splice(ix, 1);
    };
    
    CustomEventTarget.prototype.dispatchEvent= function(evt) {
        var listeners= this._getListeners(evt.type, false).slice();
        for (var i= 0; i<listeners.length; i++)
            listeners[i].call(this, evt);
        return !evt.defaultPrevented;
    };
    

    Caution: the above code is off the top of my head and untested, but may work. However it has limitations like only supporting the dispatchEvent return value if the Event object supports the DOM Level 3 defaultPrevented property, and no support for DOM Level 3 stopImmediatePropagation() (which is impossible to implement unless you rely on your own Event object that exposes a property for it). Also there’s no implementation of hierarchy or capture/bubbling.

    So IMO: you don’t gain much by trying to write code that participates in the DOM Events model. For plain-JS callback work I’d just go with your own ad hoc implementation of listener-lists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just found out that Firefox is natively supporting mouseenter and mouseleave events. This
I just found out that to simulate a click I can call element.InvokeMember(click); where
I just found out that floating an element will also make it a block,
I just found out that I can compare null with an Object like this,
Just found out that the video output of the iPad is not a system
I just found out that every time onclick event for my <button> placed inside
I just found out that in FF, if you are dynamically creating an OPTION
I just found out that lazy loading in Entity Framework only works from the
I've just found out that there is a possibility to host a Windows Forms
I have an interview tomorrow morning and just found out that I will also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.