A JavaScript Module Pattern 1
This is the first episode in the collection of Great Javascript articles by world’s top-notched Javascript gurus.
Our entry this week was written by Eric Miraglia originally posted on Y!UI Blog.
Global variables are evil. Within YUI, we use only two globals: YAHOO and YAHOO_config. Everthing in YUI makes use of members within the YAHOO object hierarchy or variables that are scoped to such a member. We advise that you exercise similar discipline in your own applications, too.
Douglas Crockford has been teaching a useful singleton pattern for achieving this discipline, and I thought his pattern might be of interest to those of you building on top of YUI. Douglas calls this the “module pattern.” Here’s how it works:
continue reading »