... mentioned in the Gang of Four’s
Design Patterns says “Program to an interface, not an implementation,” telling you how funda-
mental this concept is.
The problem is that JavaScript has no built-in ... you start implementing complex systems using design patterns.
It might seem like interfaces reduce JavaScript s flexibility, but they actually improve it by allow-
ing your objects t...
... 11/15/ 07 10:34 AM Page 52
// Later in your page, another programmer adds
var resetProduct = $('reset-product-button');
var findProduct = $('find-product-button'); // The findProduct ... new Author('Dustin Diaz', [&apos ;JavaScript Design Patterns& apos;]);
author[1] = new Author('Ross Harmes', [&apos ;JavaScript Design Patterns& apos;]);
auth...
... styles) {
for ( var prop in styles ) {
if (!styles.hasOwnProperty(prop)) continue;
setStyle(el, prop, styles[prop]);
}
}
CHAPTER 10 ■ THE FACADE PATTERN 145
908Xch10.qxd 11/15/ 07 10: 57 AM Page 145
var ... a collection of poorly designed
APIs by wrapping them in a single well-designed API.
JavaScript Libraries As Facades
JavaScript libraries are built for humans. They’re designed to sa...
... Protection Proxy
The virtual proxy is probably the most useful type of proxy to JavaScript programmers. Let’s
briefly go over the other types and explain why they aren’t as applicable to JavaScript.
A ... 14 ■ THE PROXY PATTERN206
908Xch14.qxd 11/15/ 07 11:05 AM Page 206
The Proxy Pattern vs. the Decorator Pattern
A proxy is similar to a decorator in many ways. Both decorators and virtua...
... instantiate.
Benefits of the Proxy Pattern
Each type of proxy has a different set of benefits. The remote proxy allows you to treat a remote
resource as a local JavaScript object. This is obviously ... subject.
The protection proxy controls which clients can access methods of the real subject. It is
impossible to implement in JavaScript and was ignored in this chapter.
The remote proxy...