... 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 save time, ... of setCSS:
function setCSS(el, styles) {
for ( var prop in styles ) {
if (!styles.hasOwnProperty(prop)) continue;
setStyle(el, prop, styles[prop]);
}
}
CHAPTER 10 ■ THE FACADE PATTERN 145
908Xch10...
... tools in the object-oriented JavaScript programmer’s
toolbox. The first principle of reusable object-oriented design mentioned in the Gang of Four’s
Design Patterns says “Program to an interface, ... 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...
... creation
of very modular and decoupled user interfaces.
CHAPTER 16 ■ THE COMMAND PATTERN2 26
908Xch 16. qxd 11/ 16/ 07 10:31 AM Page 2 26
Creating Commands with Closures
There is another way to create ... implements ReversibleCommand
this.cursor = cursor;
};
CHAPTER 16 ■ THE COMMAND PATTERN2 36
908Xch 16. qxd 11/ 16/ 07 10:31 AM Page 2 36
Example: Animation
Animation is a great starting...
... */
function findProduct(id) {
}
CHAPTER 5 ■ THE SINGLETON PATTERN 66
908Xch05.qxd 11/15/07 10: 36 AM Page 66
more than one superclass; you cannot do that in JavaScript because the prototype attribute
can ... Later in your page, another programmer adds
var resetProduct = $('reset-product-button');
var findProduct = $('find-product-button'); // The findProduct fun...
... our interface.
Function.prototype.method = function(name, fn) {
this.prototype[name] = fn;
return this;
};
CHAPTER 6 ■ CHAINING 86
7257ch06a.qxd 11/15/07 10:37 AM Page 86
the method or attribute ... common features that JavaScript libraries
offer, and take it from there. The fundamentals that you will find in nearly all JavaScript
libraries are shown in Table 6- 1.
Table 6- 1. The C...
... bicycle;
};
/* GeneralProductsBicycleShop class. */
var GeneralProductsBicycleShop = function() {};
extend(GeneralProductsBicycleShop, BicycleShop);
GeneralProductsBicycleShop.prototype.createBicycle ... code produced will be more modular and more maintainable.
CHAPTER 9 ■ THE COMPOSITE PATTERN1 26
908Xch09.qxd 11/ 16/ 07 10:30 AM Page 1 26
extend(OfflineHandler, SimpleHandler);
OfflineHa...
... 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 PATTERN2 06
908Xch14.qxd 11/15/07 11:05 AM Page 2 06
The Proxy Pattern vs. the Decorator Pattern
A proxy is similar to a decorator in many ways. Both decorators and virt...