Spider embraces JavaScript prototype OOP by adding 2 keywords: extends and super.
- What are they?
- What problems do they solve?
- When are they appropriate and when not?
Spider embraces JavaScript prototype OOP by adding 2 keywords: extends and super.
The
extendskeyword allows you to inherit an existing object. For example, let's say you have anAnimalobject:You can now create another object that inherits
Animalusing the extends keyword:When you create a new
Spiderobject, you'll automatically have yourwalkmethod becauseSpiderextendsAnimal.Spider (the language) also provides the
superkeyword which allows you to easily access the object you are extending. For example:Implementation
This code in Spider:
compiles to the following JavaScript: