I inherited some code that essentially does this:

user = deserializeUser(params); //var seemingly omitted by design
initViewPort();

initViewPort() in turn calls:

initHeaderPanel();
initMenuPanel();
initQuotesPanel();

Each of the above three methods subsequent to initViewPort() relies on
the availability of the global "user" variable.  I can think of two
way to obviate this reliance on a non-name-spaced global variable, and
one of those ways should be apparent based on my reference to "non-
namespaced", and that would be to provide a namespace and a getter
method, something such as:

namespace.context.getUser(); //returns object

So that the beginning of my code might be more like:

var user = deserializeUser(params);
namespace.context.setUser(user);
initViewPort();

Then at the top of initHeaderPanel, initMenuPanel & initQuotesPanel I
would do:

var user = namespace.context.getUser();

So that is one possibility.  The other way I'm considering is to pass
user around thusly:

var user = deserializeUser(params);
initViewPort(user);

And then:

initHeaderPanel(user);
initMenuPanel(user);
initQuotesPanel(user);

Am interested in the group's views on the pros and cons of these
approaches.

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to