Does JavaScript really have polymorphism?

Shaquil Hansford
9 min readFeb 19, 2021

The answer is yes, but the reason isn’t what you expect.

Photo by Tumisu on Pixabay.com

Wikipedia defines Polymorphism as:

The provision of a single interface to entities of different types or the use of a single symbol to represent multiple different types

Don’t worry! I’ll give you a plain English translation of that definition — but first, I want to tell you a story.

These past few months, I’ve been working on a project called BuddyViewer, my personal solution to the problem of watching YouTube videos simultaneously with friends remotely. My friends and I love watching YouTube, but we live very far apart right now, and we needed an alternative to the existing websites that allow us to watch videos together.

So, I had my friends create a short list of things they felt were missing from the existing websites — and sure enough, the ability to watch videos from sites outside of YouTube came up. That problem in particular has no current elegant solutions. What if you want to go from watching Minecraft on YouTube to watching anime on crunchyroll?

This presented me with an interesting problem: I needed to write code that would allow a user to interact with a video, but I had no way of knowing the specific type of video beforehand. This meant I had no way of knowing the particular…

--

--

Shaquil Hansford

I'm a full stack web developer currently available for contract, freelance or full-time job opportunities. Follow me at https://twitter.com/shaquilhansford