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 9153141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:13:01+00:00 2026-06-17T12:13:01+00:00

From within a function like: function eventHandler(e) { // … } is there a

  • 0

From within a function like:

function eventHandler(e) {
  // ...
}

is there a reliable and efficient way to determine whether e is a DOM event?

  • 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-06-17T12:13:03+00:00Added an answer on June 17, 2026 at 12:13 pm

    I don’t believe there is a reliable way to determine if a given object is NOT a DOM event.

    1. typeof e will always return 'object' for genuine Event objects, which is not helpful.
    2. Any property that you might check for on the object can exist in both a genuine Event object or any non-Event object.
    3. You might think that the prototype chain could be of use in determining this, but it has the same problem as #2 (can easily be replicated).
    4. The contructor property might seem promising, but one could do this:
    function DummyEvent(){
        this.constructor.toString = function(){
            return "function MouseEvent() { [native code] }";
        }
    }
    

    This ends up making console.log(e.constructor) print "function MouseEvent() { [native code] }"

    So, is there a “reliable” way to tell if an object is an event? No.

    Edit — Note that all of this is irrelevant if you want to prevent event spoofing as you can create real events easily.

    var evt = new Event('click');
    var evt2 = document.createEvent('MouseEvents');
    evt2.initMouseEvent('click', ...);
    //etc
    

    Edit2 — I’ve created a test jsFiddle trying to find some way to distinguish objects, but I haven’t found anything definite yet. Note that I didn’t bother to specify properties on the DummyEvent because those can obviously easily be spoofed.

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

Sidebar

Related Questions

I'm struggling to find a way to use function from within a wxPython event
I would like to call the following event handler from within another function without
I'd like to spawn several graphics windows from within a function in R using
I would like to call an external script from within a function, for instance:
I can access $conn from within my function like so: function xyz($a){ global $conn;
I'd like to get the function name from within the function, for logging purposes.
I have to allocate a struct from within another function, obviously using pointers. I've
I want to call a copyFile function from within the source file to be
I am trying to use a PHP function from within a public static function
I am trying to update my Activity's ListView from within the onLocationChanged function of

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.