O'Reilly logo

Pro JavaScript™ Design Patterns by Dustin Diaz, Ross Harmes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 16The Command Pattern

In this chapter, we take a look at a way to encapsulate the invocation of a method. The command pattern is different from a normal function in several ways: it provides the ability to parameterize and pass around a method call, which can then be executed whenever you need it to be. It also allows you to decouple the object invoking the action from the object implementing it, thus providing a huge degree of flexibility in swapping out concrete classes. The command pattern can be used in many different situations, but it is very useful in creating user interfaces, especially when an unlimited undo action is required. This pattern can also be used in place of a callback function, as it allows greater modularity in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required