Titanium Appcelerator Quickie: Callbacks Are Your Friend - Clearly Innovative | Web and Mobile DevelopmentClearly Innovative | Web and Mobile Development

Published on October 11, 2011 by Aaron Saunders (Platform Evangelist)

We all know from reading the Appcelerator wiki about Javascript best practices that global variables and polluting the global namespace are no-nos when writing good, maintainable code. However, we also know that old habits are hard to break – we are writing the code, we need “this” value set? Who cares?! Just create a global and be done with it!

The problem with this approach is that it will eventually come back to bite us; we will forget about the global variable, someone else won’t be aware of it and, consequently, they will create some other way to get the same information. Worst of all – it won’t always work.

Three notes we need to write on bright yellow stickies and attach to our monitor:

  • We are going to write modular code (from now on, at least)
  • Event-based programming is a good thing
  • Global variables should be used only as a last resort

See Complete Posting On Appcelerator Developer Blog

Source Code Available Here