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
extends
keyword allows you to inherit an existing object. For example, let's say you have anAnimal
object:You can now create another object that inherits
Animal
using the extends keyword:When you create a new
Spider
object, you'll automatically have yourwalk
method becauseSpider
extendsAnimal
.Spider (the language) also provides the
super
keyword which allows you to easily access the object you are extending. For example:Implementation
This code in Spider:
compiles to the following JavaScript: