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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:38:02+00:00 2026-06-11T09:38:02+00:00

I have been trying out some different ways to organize my code in my

  • 0

I have been trying out some different ways to organize my code in my javascript applications and i wonder which one is the most appropriate.

First example:

var Application = {

    init: function() {
        //Some code
        Calculate();
    },

    Calculate: function() {
        //Some code
    }
};

Second example:

(function() {

    function init() {
        //Some code
        Calculate();
    }

    function Calculate() {
        //Some code
    }

})();

Third example:

(function() {

    var init = function() {
        //Some code
        Calculate();
    };

    var Calculate = function() {
        //Some code
    };

})();

Or is it some other way that is preferred? I get very confused over this. Thanks in advance!

  • 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-11T09:38:03+00:00Added an answer on June 11, 2026 at 9:38 am

    The answer is, without question, “it depends.” How big is your application? Do you need all of the modules all of the time? How scalable and reusable does your app need to be? These are not JavaScript questions specifically, but rather “architectural” questions, and while learning JavaScript basics is relatively easy, it takes a lot of years to learn to be a good architect in software development. (though it is excellent that you are asking these questions.)

    I would encourage you to dive into programming patterns. Learning patterns is learning to structure an application in the right way, depending on the given application.

    I can say that a combination of your first example and your second example are a good place to start (an instantly invoked function expression wrapping and returning an object literal). This gives a degree of private scope via closure, and is called the Module Pattern. You will see this pattern used to some degree in almost all major JS applications and libraries because of its versatility and elegance.

    To learn more about JavaScript patterns, I highly recommend Addy Osmani’s “Learning JavaScript Design Patterns.” You can read it for free, here: http://addyosmani.com/resources/essentialjsdesignpatterns/book/

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

Sidebar

Related Questions

I have been trying out Cassandra and need some help in understanding a few
I have been trying to figure this out for some time. It seems lots
I have been trying to figure out how to read paragraph content which exists
I have been trying to find out why the following lines of code do
i have been trying to figure this out but i just can't.... for some
I have been trying to create a web service out some python scripts, and
I have been trying out some basic exercises involving loops. Can someone tell me
i have been trying to figure out ways where i can return more than
I have been trying to find out how android relocates UI elements on different
I have been trying out the MoreLikeThis Bundle to bring back a set of

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.