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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:02:08+00:00 2026-05-26T04:02:08+00:00

My JavaScript file is now more than 1000 lines long. I need to make

  • 0

My JavaScript file is now more than 1000 lines long. I need to make it more manageable. Here is the basic structure of my file:

// Some settings (easily put in a separate file)

// Some jQuery plugins (easily put in a separate file)

$(function () {
   var gadget1 = (function() {
       var private, public;
       // stuff
       return public;
   }());

   var gadget2 = (function() { // gadget2 uses gadget1
       var private, public;
       // stuff
       return public;
   }());

   var gadget3 = (function() {  // gadget3 uses gadget1 and gadget2
       var private, public;
       // stuff
       return public;
   }());

   // Playing around with the gadgets.
});

The bulk of my code is wrapped in $(document).ready() and is made of “gadgets” that are chunky closures. How can I separate each “gadget” in a separate module?

  • 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-26T04:02:09+00:00Added an answer on May 26, 2026 at 4:02 am

    You can use the namespacing pattern

    MyAPP = {}
    MyAPP.Gadget1 = (function () {
        //blah blah
    })()
    

    and then have a helper

    MyAPP.helpers = (function () {
      //here are my helper functions/properties etc.
    })()
    

    These namespaced objects would be in separate files.

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

Sidebar

Related Questions

I create a file in JavaScript. Now I want to be able to make
Now that JavaScript libraries like jQuery are more popular than ever, .js files are
I wrote a page by javascript that has over 1000 lines of code and
I have a javascript file that reads another file which may contain javascript fragments
The size of my JavaScript file is getting out of hand because I have
I have an external Javascript file and i am trying to alert the value
I have a JavaScript file which is loaded up at the end of my
I have a lengthy JavaScript file that passes JSLint except for used before it
If a third party javascript file hangs and takes a while to load, will
I have a simple JavaScript file that has three jQuery $document.ready functions. All three

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.