O'Reilly logo

Learning Object-Oriented Programming by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required