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 ...

Get Pro JavaScript™ Design Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.