Note that there are some explanatory texts on larger screens.

plurals
  1. POPrivate var aiming at globar var does not change when the global changes
    primarykey
    data
    text
    <p>I am trying to break my code into modules, and I have problems referencing the other modules of my app.</p> <pre><code>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); </code></pre> <p>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.</p> <p>This is the way "funcs" gets more methods... when I execute the method MYAPP.funcs.init() the MYAPP.funcs is re-written by itself.</p> <pre><code>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)); </code></pre> <p>Thanks in advance!!</p> <hr> <p>In case it is interesting for anybody...</p> <p>The method I am using for moduling is the "tight augmentation" <a href="http://webcache.googleusercontent.com/search?hl=es-419&amp;q=cache%3Aadequatelygood.com%2F2010%2F3%2FJavaScript-Module-Pattern-In-Depth&amp;btnG=" rel="nofollow">http://webcache.googleusercontent.com/search?hl=es-419&amp;q=cache%3Aadequatelygood.com%2F2010%2F3%2FJavaScript-Module-Pattern-In-Depth&amp;btnG=</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload