Object-orientation, prototyping, and inheritance
So far, we haven't talked about inheritance in JavaScript, so let's do this now.
It's useful to share behaviour within a certain class of objects, but there are cases where we would like to share behaviour between different, but similar classes of objects.
Imagine our virtual world not only had cars, but also bikes. Both drive, but where a car has a horn, a bike has a bell.
Being able to drive makes both objects vehicles, but not sharing the honk and ring behaviour distinguishes them.
We could illustrate their shared and local behaviour as well as their relationship to each other as follows:

Designing this relationship in a class-based language like Java is straightforward: We would define a class Vehicle
with a method drive
, and two classes Car
and Bike
which both extend the Vehicle
class, and implement a honk
and a ring
method, respectively.
This would make the car
as well as bike
objects inherit the drive
behaviour through the inheritance of...