Working with duck typing in JavaScript

We will create an Animal constructor function and customize its prototype to generalize all the requirements for animals. We will create two constructor functions: Dog and Frog that will use Animal as its prototype. Then, we will create a Party constructor function that will be able to work with instances of any object that includes Animal in its prototype chain through duck typing. We will work with the party of dogs and the party of frogs.

Then, we will create a HorseDeeJay constructor function and generate a new version of the Party constructor function that will work with any object that includes Animal in its prototype and any object that provides the properties and methods declared in the HorseDeeJay ...

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