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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.