Duck typing

We introduced the concepts of contract and interface and mentioned how interfaces are defined in two well-known strongly typed languages. Contracts enforced by the implementation of interfaces would allow us to solve the problem of hiring just developers, that is, persons able to write code. However, we saw that interfaces in languages such as C# and Java rely on their type checking system. How can we benefit from contracts and interfaces in JavaScript?

JavaScript neither has a native support of interfaces nor allows us to define new types. Moreover, it is an extremely dynamic language that not only allows to create objects with specific members but also to change their structure at runtime so that we cannot make any assumptions based ...

Get Mastering JavaScript Object-Oriented Programming 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.