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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.