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