CHAPTER 2Interfaces

The interface is one of the most useful 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, not an implementation," telling you how fundamental this concept is.

The problem is that JavaScript has no built-in way of creating or implementing interfaces. It also lacks built-in methods for determining whether an object implements the same set of methods as another object, making it difficult to use objects interchangeably. Luckily, JavaScript is extremely flexible, making it easy to add these features.

In this chapter, we look at how other object-oriented languages implement interfaces, ...

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.