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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:32:31+00:00 2026-06-12T12:32:31+00:00

I am trying to break my code into modules, and I have problems referencing

  • 0

I am trying to break my code into modules, and I have problems referencing the other modules of my app.

MYAPP = (function(my_app)
{

    var funcs = my_app.funcs;

    var module2 =
    {
         stupid_function = function ()
         {
            var some_var = "auwesome!";

            //let's call something from the other module...
            funcs.do_whatever();
         };

    };

    my_app.module2 = module2;

    return my_app;

})(MYAPP);

The problem comes when MYAPP.funcs changes. For example, when I initialize it and add new methods… since “funcs” was created inside of the closure, it has a copy of MYAPP.funcs and does not have the new stuff I need.

This is the way “funcs” gets more methods… when I execute the method MYAPP.funcs.init() the MYAPP.funcs is re-written by itself.

var MYAPP = (function (my_app, $)
{

    'use_strict';

     my_app.funcs = {};

         my_app.funcs.init = function ()
         {
            panel = my_app.dom.panel;
            funcs = my_app.funcs;
                query_fns = funcs.query;

                 my_app.funcs =
                 {
                       some_method: function () { ... },
                       do_whatever: function () { ... }
                 };

          };


    return my_app;

}(APP, jQuery));

Thanks in advance!!


In case it is interesting for anybody…

The method I am using for moduling is the “tight augmentation” http://webcache.googleusercontent.com/search?hl=es-419&q=cache%3Aadequatelygood.com%2F2010%2F3%2FJavaScript-Module-Pattern-In-Depth&btnG=

  • 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-12T12:32:33+00:00Added an answer on June 12, 2026 at 12:32 pm

    Nothing to do with modules or global… the difference is if you are changing object variable points to or what variable is pointing to:

    var first = {my:"test"};
    var second = first; // second points to object {my:"test"}
    first.foo = 42; // updating the object, second points to it and can see the change
    first = {my:"other"}; // new object, second still points to old  {my:"test", foo:42}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to break some of my old habits of writing bad code.
New programmer here, I am trying to understand and break down this code below
I am trying to break a huge SQL file into little sql file and
I have the vector output = PV_out(:); I am trying to break this down
I am trying to break a large string of text into several smaller strings
I am trying to integrate the following into my code to unregister phonestatelistener TelephonyManager
I'm looking for a way to break into the debugger from Java code, without
I've run into some problems while trying to write a smallshell in c. The
I'm not very familiar with RhinoMocks and I'm trying to break into TDD on
Im trying to break the input and the processing into two parts so that

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.