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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:39:41+00:00 2026-05-25T11:39:41+00:00

When I validate the following code with jslint I get the following errors. function

  • 0

When I validate the following code with jslint I get the following errors.

function displayMegaDropDown() {
"use strict";
var liMegaPosition, divMegaOffset;
liMegaPosition = jQuery(this).position();
divMegaOffset = { top: liMegaPosition.top + jQuery(this).height(), left: liMegaPosition.left };
jQuery(this).find("div").offset(divMegaOffset);

jQuery(this).addClass("hovering");
}

Problem at line 4 character 29: Strict violation.

 liMegaPosition = jQuery(this).position();  

Problem at line 5 character 56: Strict violation.

divMegaOffset = { top: liMegaPosition.top + jQuery(this).height(), left: liM...

Problem at line 6 character 12: Strict violation.

jQuery(this).find("div").offset(divMegaOffset);

Problem at line 8 character 12: Strict violation.

jQuery(this).addClass("hovering");

I’m guessing that it’s because of the use of jQuery(this) but I don’t understand what to replace it with. Note that this is not because jQuery isn’t declared as a global.

  • 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-25T11:39:42+00:00Added an answer on May 25, 2026 at 11:39 am

    I think the problem is that you use this not inside of a method. The following code

    /*global jQuery */
    var myObj = {
        myNethod: function displayMegaDropDown() {
            "use strict";
            var ts = jQuery(this),
                liMegaPosition = ts.position(),
                divMegaOffset = {
                    top: liMegaPosition.top + ts.height(),
                    left: liMegaPosition.left
                };
    
            ts.find("div").offset(divMegaOffset);
    
            ts.addClass("hovering");
        }
    };
    

    or this one

    /*global jQuery */
    function displayMegaDropDown(t) {
        "use strict";
        var ts = jQuery(t),
            liMegaPosition = ts.position(),
            divMegaOffset = {
                top: liMegaPosition.top + ts.height(),
                left: liMegaPosition.left
            };
    
        ts.find("div").offset(divMegaOffset);
    
        ts.addClass("hovering");
    }
    

    will give you no errors or warnings.

    UPDATED: One more version, which is very close to your original one, also has not errors or warnings:

    /*global jQuery */
    var displayMegaDropDown = function () {
        "use strict";
        var ts = jQuery(this),
            liMegaPosition = ts.position(),
            divMegaOffset = {
                top: liMegaPosition.top + ts.height(),
                left: liMegaPosition.left
            };
    
        ts.find("div").offset(divMegaOffset);
    
        ts.addClass("hovering");
    };
    

    UPDATED 2: I find the question interesting for understanding. So I look through ECMAScript standard . I find the following in the “Annex C (informative) The Strict Mode of ECMAScript” (see better in HTML version here):

    If this is evaluated within strict mode code, then the this value is
    not coerced to an object. A this value of null or undefined is not
    converted to the global object and primitive values are not converted
    to wrapper objects. The this value passed via a function call
    (including calls made using Function.prototype.apply and
    Function.prototype.call) do not coerce the passed this value to an
    object (10.4.3, 11.1.1, 15.3.4.3, 15.3.4.4).

    I suppose that it is the reason of the JSLint error.

    Of cause if you would switch off the strict mode the code will have no more errors:

    /*global jQuery */
    /*jslint sloppy: true */
    function displayMegaDropDown() {
        var ts = jQuery(this),
            liMegaPosition = ts.position(),
            divMegaOffset = {
                top: liMegaPosition.top + ts.height(),
                left: liMegaPosition.left
            };
    
        ts.find("div").offset(divMegaOffset);
    
        ts.addClass("hovering");
    }
    

    UPDATED 3: It seems that impossibility of the usage of this in the function statement and the possibility of the usage of this in the function expression seems suspected for many people. Today I received one more comment about this. So I created very simple demo

    /*jslint devel: true */
    (function () {
        'use strict';
        function test() {
            alert(this);
        }
    
        test();
    }());
    

    You can test it here that in IE9 the demo display alert with the text “[object Window]” and on the current versions of Chrome and Firefox you will see “undefined”.

    So the problem with the usage of this in function statement is not “a jslint thing”. It’s real problem which you should take in considerations during development of your JavaScript programs.

    I personally prefer to use function expression and almost never use more function statements. I think that the people who come from another program languages (like me too) try at the beginning to use the same construction which was good in your favorite languages. Only later one finds out that definition of variables in block is bad (there are no block level scope in JavaScript) and that function statements is not always the best choice too.

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

Sidebar

Related Questions

No related questions found

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.