How would I use proto-types of proto-types in the workplace?

Hey everyone,

I am just completed this exercise: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-prototype-chain

However, I’m struggling to see a real world use for accessing the prototypes of my of my Object’s prototypes. In the exercise we test to see if the protoype of all objects is also a protoype of Dog.prototype. Could someone give me an example of how one might use this functionality in building website or online application? I’m sure it exists, I just have a hard time seeing it.

Hello!

You would use it when you need some kind of abstraction.

For example, if you had to build a shopping cart but you needed to support different payment gateways, you would define the common functionality as a base prototype. Then the developers that implement the gateways (paypal, stripe, etc.) would extend that prototype. We would use the prototype checking to determine which gateways implement the base Gateway.

Here’s a sample code you can tamper with: https://jsfiddle.net/skaparate/7rqmdnt2/

Hope it helps :slight_smile:.

1 Like