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

  • Home
  • SEARCH
  • 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 953785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:06:26+00:00 2026-05-16T00:06:26+00:00

I understand why JSLint kicks up a warning here, but I don’t know how

  • 0

I understand why JSLint kicks up a warning here, but I don’t know how else to write my code so it validates.

Here’s a boiled down sample. In the code below, I have an object that I need to attach two event listeners to: one for “complete” and the other for “error”. Each points to its own event handler. When either event handler is reached, I want to remove both event handlers. But I will always get a validation error when I try to remove the second event handler’s listener from the first event handler.

var myFunction = function(obj) {
    var doComplete = function() {
        // ...Do something here to handle successful execution, then remove listeners
        obj.removeEventListener('complete',doComplete,true);
        obj.removeEventListener('error',handleError,true); // INVALID!
    };
    var handleError = function() {
        // ...Do some error handling here and then remove event listener
        obj.removeEventListener('complete',doComplete,true);
        obj.removeEventListener('error',handleError,true);
    };

    obj.addEventListener('complete',doComplete,true);
    obj.addEventListener('error',handleError,true);
    obj.load();
};

Whenever I get one of these warnings, it has always meant I’m doing something wrong, but in this case, I can’t see how to get around the problem. Does anyone know what the right way is to do this?

The validation error is:
Lint at line 5 character 41: 'handleError' is not defined. (the web client says Implied global: handleError 5)

  • 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-16T00:06:27+00:00Added an answer on May 16, 2026 at 12:06 am

    You need to rearrange your code slightly.

    var myFunction = function(obj) {
        var doComplete, handleError;
        doComplete = function() {
            // ...Do something here to handle successful execution, then remove listeners
            obj.removeEventListener('complete',doComplete,true);
            obj.removeEventListener('error',handleError,true); // INVALID!
        };
        handleError = function() {
            // ...Do some error handling here and then remove event listener
            obj.removeEventListener('complete',doComplete,true);
            obj.removeEventListener('error',handleError,true);
        };
    
        obj.addEventListener('complete',doComplete,true);
        obj.addEventListener('error',handleError,true);
        obj.load();
    };
    

    JSLint expects to see a declaration of a variable before it’s used. This change does so, even though it appears ineffective.

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

Sidebar

Related Questions

I don't understand why I get the error message when I run JSLint with
I understand what System.WeakReference does, but what I can't seem to grasp is a
I understand the difference between String and StringBuilder ( StringBuilder being mutable) but is
I understand that they are both supposed to be small, but what are the
I'm reading the JSlint Options Documentation to understand each of the available options, and
I'm trying to get my Javascript code 100% JSLint clean. I've got some JS
I understand the difference between a Mock and a Stub. But different types of
I understand there is a method send for xmlHttpRequest objects, but I've been working
I'm trying to understand why JSLint complains about an implied global variable in the
I understand that if else staments should say stuff like: if dog equals one,

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.