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 on instance type or other similar static information. However, we can try to define contracts using the so called duck typing.
Duck typing is a programming technique where a contract is established between a function and its caller, requiring the...