Checkpoint: More Structure
- Like the HTML, the JavaScript we just wrote has structure. It's composed of a main function hung on a single variable,
SEARCH, and an anonymous support function that automatically fires when the window is done loading.
- Why is this important? If we hang everything on one single variable, it will be much more difficult for other JavaScript programs--third-party advertising, for example, or somebody's random Wordpress plug-in--to screw things up later.
- To phrase it succinctly:
global variables are evil. Douglas Crockford has an excellent article on this, on the Yahoo User Interface blog, here: http://yuiblog.com/blog/2006/06/01/global-domination.
- Yes, this stuff gets confusing, so:
Remember to cheat when necessary!
- URL for copy and paste is at the bottom of this screen.
prev - http://kentbrewster.com/build-a-search-app/code/code3.html - next