Coding patterns
Let's start with some patterns that reflect JavaScript's unique features. Some patterns aim to help you organize your code, for example, namespacing; others are related to improving performance, such as lazy definitions and init-time branching; and some make up for missing features, such as private properties. The patterns discussed in this section include the following topics:
- Separating behavior
- Namespaces
- Init-time branching
- Lazy definition
- Configuration objects
- Private variables and methods
- Privileged methods
- Private functions as public methods
- Immediate functions
- Chaining
- JSON
Separating behavior
As discussed previously, the three building blocks of a web page are as follows:
- Content (HTML)
- Presentation (CSS)
- Behavior (JavaScript)
Content
HTML is the content of the web page, the actual text. Ideally, the content should be marked-up using the least amount of HTML tags that sufficiently describe the semantic meaning of that content. For example, if you're working on a navigation...
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime