Summary
This chapter focused on using duck typing instead of relying on type checking. We see how the dynamic nature of JavaScript and its type system do not allow us to process objects in a reliable way. The structure of an object can change dynamically and establishing the type of instance of an object that may be very difficult, for example, when multiple inheritance is applied. Therefore, we introduced the concept of a contract between objects and the support of interfaces provided by classical OOP languages.
Since JavaScript does not support interfaces, we explored the duck typing technique in order to describe and check the contract's compliance. Duck typing allows us to process objects focusing on how an object behaves instead of relying ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access