Sample Chapter — Pro JavaScript Design Patterns by Ross Harmes and Dustin Diaz

By YUI TeamDecember 17, 2007

Fellow Yahoo Ross Harmes and former Yahoo (current Googler) Dustin Diaz have collaborated on a new book from Apress, Pro JavaScript™ Design Patterns. As the title suggests, this volume focuses on the implementation of common object-oriented design patterns in the JavaScript language. Ross and Dustin "wanted to show programmers that JavaScript contains features on par with other high-level languages and is an object-oriented programming language in its own right."

Ross, Dustin and their Apress editors were kind enough to let us share a chapter of the book here on YUIBlog:

  • Chapter 9: The Flyweight Pattern — "[The Flyweight pattern is] most useful in
    situations where large numbers of similar objects are created, causing performance problems. This pattern is especially useful in JavaScript, where complex code can quickly use up all of the available browser memory. By converting many independent objects into a few shared objects, you can reduce the amount of resources needed to run web applications. The benefit of this can vary widely. For large applications that can potentially be used for days at a time without being reloaded, any technique that reduces the amount of memory used can have a very positive effect."

For more on the design patterns covered in the book and information about where to buy it, check out the website. The e-Book version is also available from Apress.

Congratulations to Dustin and Ross on getting this book done and contributing to the growing conversation about the role of design patterns in the JavaScript language.