Book Image

Object-Oriented JavaScript

Book Image

Object-Oriented JavaScript

Overview of this book

Table of Contents (18 chapters)
Object-Oriented JavaScript
Credits
About the Author
About the Reviewers
Preface
Built-in Functions
Regular Expressions
Index

Coding Patterns


This first part of the chapter discusses some patterns that reflect JavaScript's unique features. Some patterns aim to help you with organizing your code (such as namespace patterns), others are related to improving performance (such as lazy definitions and init-time branching), and some make up for missing features such as privately scoped properties. The patterns discussed in this section include:

  • Separating behavior

  • Namespaces

  • Init-time branching

  • Lazy definition

  • Configuration objects

  • Private variables and methods

  • Privileged methods

  • Private functions as public methods

  • Self-executable functions

  • Chaining

  • JSON

Separating Behavior

As discussed previously, the three building blocks of a web page are:

  • Content (HTML)

  • Presentation (CSS)

  • Behavior (JavaScript)

Content

HTML is the content of the web page; the actual text. The content should be marked up using the smallest amount of HTML tags that sufficiently describe the semantic meaning of that content. For example, if you're working on a navigation...