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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:27:23+00:00 2026-05-27T10:27:23+00:00

In Javascript I have code like: document.addEventListener("mousedown", mouseDownHandler); and occasionally I might fat finger

  • 0

In Javascript I have code like:

document.addEventListener("mousedown", mouseDownHandler);

and occasionally I might fat finger something like:

document.addEventListener("mouzedown", mouseDownHandler);

And Javascript won’t recognize that I’m a moron and I’ll be confused why my handler isn’t working.

Actionscript3 specifies event constants like so:

MouseEvent.MOUSE_DOWN // equiv to the String "mouseDown"

If I fat-finger a variable or constant then JS gets mad at me and I can solve the problem real quick. Does JavaScript have anything similar to to this or do I need to make my own JS pseudo-constants for event types?

  • 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-27T10:27:24+00:00Added an answer on May 27, 2026 at 10:27 am

    There is no built-in feature to do this for you.

    You could create your own list of events:

    var EventNames = {
      MOUSE_DOWN : "mousedown",
      MOUSE_UP   : "mouseup",
      CLICK      : "click",
      // etc
    };
    

    But that doesn’t protect you from typos because then EventNames.MOUZE_DOWN will just give you undefined (which will likely be accepted by addEventListener() but – obviously – not do what you want).

    You could create a series of individual global variables and then the browser should give an error if you make a typo on the “constant” name (and your IDE or lint product may detect typos for you):

    var Event_MOUSE_DOWN = "mousedown",
        Event_MOUSE_UP   = "mouseup",
        // etc
    

    But of course members of the “globals are evil” brigade are already starting to froth at the mouth just from having read the above. You could do the above without globals by wrapping all of your code (including those “constants”) in one big immediately-executed anonymous function, or you could instead do something like this:

    // YNH: "Your Namespace Here" (insert your own namespacing
    //                             code as desired)
    var YNH_Events = {
       validEvents : ["mouseup","mousedown","click","etc"],
    
       bindEvent = function(element, eventType, handler, isCustomEvent) {
          if (!isCustomEvent && -1 === this.validEvents.indexOf(eventType))
             throw "Invalid event type requested: " + eventType;
    
          if (element.addEventListener)
             element.addEventListener(eventType, handler, false);
          else if (element.attachEvent)
             element.attachEvent("on" + eventType, handler);
          else
             element["on" + eventType] = handler;
       }
    }
    
    YNH_Events.bindEvent(someElement, "mousedown", function() { });         // OK
    YNH_Events.bindEvent(someElement, "customevent", function() { }, true); // OK
    YNH_Events.bindEvent(someElement, "mouzedown", function() { });     // Error!
    

    Of course, the usual caveat about using Array.indexOf() applies, i.e., not supported in older browsers but you can shim it as described by MDN, blah, blah, blah.

    Or you could do like jQuery and define your own .mousedown(), .click() etc methods and only attach events through those methods – you’ll definitely get an error if you mistype the method name.

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

Sidebar

Related Questions

I have the following JavaScript code which I like to convert to jQuery but
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have got some javascript code and I'd like to convert this to C#.
I'd like to execute JavaScript code from within a C# assembly and have the
I have code like: document.onmousedown = function(){ alert('test'); } Now, except the element with
i have code like this: <script type=text/javascript> var _gaq = _gaq || []; _gaq.push(['_setAccount',
I have a javascript file which has some code somewhat like this: var Slide
I have a code like this... function diagnoseprint() { document.getElementById('goeshere').innerHTML=localStorage['timetable']; var decode = JSON.parse(localStorage['timetable']);
My code is like this: <script type=text/javascript> $(document).ready(function(){ $(Edit).click(function(){ $.get('fetchvalues.php'); }); }); </script> <input
In my javascript file, I have a code snippet like: $('<form action=process.php method=POST>' +

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.