jemptymethod : > I inherited some code that essentially does this:
You should consider how these changes will affect on existing code in your application. In order to prevent incompatibilities with existing code, you should decide the best approach for you. > user = deserializeUser(params); //var seemingly omitted by design > initViewPort(); > > initViewPort() in turn calls: > > initHeaderPanel(); > initMenuPanel(); > initQuotesPanel(); The problem here is not only `user' variable. Each of `initViewPort', `initHeaderPanel', `initMenuPanel', `initQuotesPanel' are global. So they are also global pollutions. You can use the follow design: var widget = (function () { var user; //Assign a value of user function initViewPort() { //... } function initHeaderPanel() { //... } function initMenuPanel() { //... } function initQuotesPanel() { //... } return { initViewPort : initViewPort, initHeaderPanel : initHeaderPanel, initMenuPanel : initMenuPanel, initQuotesPanel : initQuotesPanel } })(); widget.initViewPort(); widget..initHeaderPanel(); widget..initMenuPanel(); widget..initQuotesPanel(); Read also: <URL:http://peter.michaux.ca/articles/how-i-write-javascript-widgets> -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com