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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:30:27+00:00 2026-06-06T13:30:27+00:00

I am trying to wrap my head around javascript modules, but I’m unsure how

  • 0

I am trying to wrap my head around javascript modules, but I’m unsure how to split up a module into further sub modules. I have read that nested functions are not really a great idea, due to performance, so how do I break up a function in a module? For example, lets say I have the following module:

var Editor = {};

Editor.build = (function () {
    var x = 100;
    return {
        bigFunction: function () {
            // This is where I need to define a couple smaller functions 
            // should I create a new module for bigFunction? If so, should it be nested in Editor.build somehow?
        }
    };
})();

bigFunction is only related to Editor.build. Should I attach the smaller functions that make up bigFunction to the prototype bigFunction object? I’m not even sure if that would make sense.

var Editor = {};

Editor.build = (function () {
    var x = 100;
    return {
        bigFunction: function () {
            bigFunction.smallFunction();
            bigFunction.prototype.smallFunction = function(){ /*do something */ };   
            // not sure if this even makes sense
        }
    };
})();

Can someone please throw me in the right direction here? There is so much misleading information online, and would just like a definite guide on how to deal with this sort of modularization.

Thank you.

  • 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-06T13:30:30+00:00Added an answer on June 6, 2026 at 1:30 pm

    Here is a snippet I use to make names for an input:

        var dynamicCounter = 0;
        //custom dropdown names
        var createContainerNames = function () {
            function Names() {
                this.id = "Tasks_" + dynamicCounter + "__ContainerId";
                this.name = "Tasks[" + dynamicCounter + "].ContainerId";
                this.parent = "task" + dynamicCounter + "Container";
            }
            Names.prototype = { constructor: Names };
            return function () { return new Names(); };
        } ();
    

    And then I use it:

        var createdNames = createContainerNames();
        var createdId = createdNames.id;
        dynamicCounter++;
        var differentNames = createContainerNames();
        var differentId = differentNames.id;
    

    Another approach would be to do this:

    var NameModule = function(){
    
     //"private" namemodule variables
     var priv1 = "Hello";
    
     //"private namemodule methods
     function privMethod1(){
      //TODO: implement
     }
    
     //"public namemodule variables
     var pub1 = "Welcome";
    
     //"public" namemodule methods
     function PubMethod(){
      //TODO: pub
     } 
    
     return {
      pub1 : pub1,
      PubMethod: PubMethod
     };
    

    and then to use it

    var myPubMethod = new NameModule();
    myPubMethod.PubMethod();
    var pubVar = myPubMethod.pub1;
    

    EDIT

    You could also take this approach:

    var mod = function(){
     this.modArray = [];
    };
    
    mod.prototype = {
    
     //private variables
     modId: null,
    
     //public method
     AddToArray: function (obj) {
        this.modArray.push(obj);
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting into JavaScript and I'm trying to wrap my head around prototypal
I'm trying to wrap my head around organising my code. I have several modules
Trying to wrap my head around the jQuery .not() function, and running into a
I'm trying to wrap my head around Object Oriented programming. But I'm having some
I'm trying to wrap my head around custom paging in the ASP.NET Gridview, but
I'm trying to wrap my head around Javascript's function.apply(). You use it like this:
I'm trying my hardest to wrap my head around JavaScript closures. I get that
I'm trying to wrap my head around this, but I seem to go in
I'm trying to wrap my head around multiple inheritance in python. Suppose I have
I'm trying to wrap my head around building a custom JavaScript library. I've read

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.