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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:14:26+00:00 2026-05-26T05:14:26+00:00

I have a massive function that I would like to decompose into multiple files.

  • 0

I have a massive function that I would like to decompose into multiple files. Here is the structure of my function:

var myFunction = function (argument) {
   var private1, private2, private3;

   var gadget1 = (function () {
       // Play around with private1, private2, private3, argument

       return gadget1API;
   }());

   var gadget2 = (function () {
       // Play around with private1, private2, private3, argument

       return gadget2API;
   }());

   var gadget3 = (function () {
       // Play around with private1, private2, private3, argument

       return gadget3API;
   }());

   return myFunctionAPI;
}

Here namespacing the gadgets to spread them over multiple files doesn’t work because they all depend upon private1, private2, private3 which are within the myFunction closure. For this to work, I would need the myFunction closure to close over 3 different files.

  • 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-26T05:14:27+00:00Added an answer on May 26, 2026 at 5:14 am

    You should create it as an object, not a closure, and load it first, something like this:

    function myObject(argument) {
       this.arg = argument;
       this.private1 = whatever;
       this.private2 = whatever;
       this.private3 = whatever;
    
       this.gadget1 = (function () {
       // Play around with this.private1, this.private2, this.private3, this.arg
    
           return gadget1API;
       }());
    
       this.gadget2 = (function () {
       // Play around with this.private1, this.private2, this.private3, this.arg
    
           return gadget2API;
       }());
    
       this.gadget3 = (function () {
       // Play around with this.private1, this.private2, this.private3, this.arg
    
           // return gadget3API; i don't see what this is for, so commented out
       }());
    
       return myFunctionAPI;
    }
    

    And instantiate it right after you defined it

    var myFunction = new myObject(theargument);
    

    you can access it’s functions like this:

    var something1 = myFunction.gadget3();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have massive directories, and I would like to read all the files as
I have a massive collection of methods that I want to shape into a
I am importing massive amounts of data from Excel that have various table layouts.
I have a tree like structure created out of models using ForeignKey linkages. As
EDIT I just realized that I must have had a massive brain fart while
I have a query that looks like the following SELECT t1.Name, t2.ID, t2.name FROM
I have a function that returns an lm object. I want to produce predicted
Alright I have what I would call a massive list of longitude and latitude
I have a button that loads a report for print into an invisible iframe
I have an images directory, some with massive resolutions, so I'd like to serve

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.