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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:30:31+00:00 2026-06-03T14:30:31+00:00

I am using the following namespacing pattern: var MyNamespace = new function () {

  • 0

I am using the following namespacing pattern:

var MyNamespace = new function () {
    var foo = function () {
        bar();
    };
    var bar = function () {
        alert("bar");
    };
    this.init = function () {
        foo();
    };
};

$(document).ready(function() {
    MyNamespace.init();
});

JSLint complains that bar is used before it’s defined. However foo is not called until after bar has been declared. The code works fine with all the browsers I have tried: http://jsfiddle.net/jDKvz/

The pattern is per How do I declare a namespace in JavaScript?, second answer.

Do I need to fix something here, or should I just ignore JSLint?

  • 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-03T14:30:33+00:00Added an answer on June 3, 2026 at 2:30 pm

    I suspect that’s because of hoisting, variables and function declarations are hoisted onto top by the interpreter, it is likely that this is how it sees it:

    var MyNamespace = new function () {
        var foo;
        var bar;
    
        foo = function () {
            bar();
        };
    
        bar = function () {
            alert("bar");
        };
    
        this.init = function () {
            foo();
        };
    };
    

    Now inside the foo = function () {bar();}; the bar() isn’t yet parsed, it is just a variable bar not a function to be called at that point.

    Having said that, if your code works fine, you can go with it, turning strict mode on is also helpful.

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

Sidebar

Related Questions

We are using following fields to do some calculation. $(document).ready(function(){ $('.num').blur(function () { var
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
I am using following for TextArea ToolBar bar = new ToolBar(box,SWT.NONE); ToolItem item =
iam using following function in my javascript code function AlphaSort(sort_type,cat_1,cat_2,cat_nm) { var len =
I am using following ajax call in my .net application. this function execute on
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
I'm using following code to alert id of current element. <input type=text id=desc name=txtTitle
I created a DB using following code. Dim conn As New SqlConnection(Server=.\SQLExpress;Data Source=;Integrated Security=SSPI)
Using following controller: class mydvbController extends Zend_Controller_Action { public function indexAction() { } public
im using following code for http-proxy: var httpProxy = require('http-proxy'); var options = {

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.