Prototypical Inheritance in JavaScript

Ruby uses classical inheritance. Everything is very explicitly an instance of something, or up top described as inheriting from another thing. Or very early on described as including a mix in, all very clearly hierarchical.

Javascript, on the other hand, uses prototypical inheritance. Rather than everything being obviously structured and a bit of a faff to refactor as your domain model evolves, as you encounter new things that are like old things you can use the following code to DRY up:

newThing = Object.create(oldThing)

Now any characteristics that the new thing doesn’t explicitly have will be drawn from the old thing, and these can be linked up on and on.

written with Toby Clarke and Raph Levy

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.