Create a class named InactiveRocket that extends the Rocket class and assigns an additional lastFlow property in the constructor. Use the name to assign the instance to the inactiveRocketMap and override the print method to include the new property:
// main.js
class InactiveRocket extends Rocket {
constructor(name, lastFlown) {
super(name);
this.lastFlown = lastFlown;
inactiveRocketMap[name] = this;
}
print() {
console.log(this.name + ' is an inactive rocket');
console.log(`${this.name} was last flown: ${this.lastFlown}`);
}
}
Add a static find method that retrieves an instance from the rocketMap:
Create a main function that creates instances of both classes and try to retrieve the instances from the maps:
// main.js
export function main() {
const saturnV = new InactiveRocket('Saturn V');
const falconHeavy = new Rocket('Falcon Heavy');
// print rocket for saturn V and falcon heavy
console.log('All Rockets:');
Rocket.find('Saturn V').print();
Rocket.find('Falcon Heavy').print();
// print inactive entry for saturn v and attempt falcon
console.log('Inactive Rockets:');
InactiveRocket.find('Saturn V').print();
// throws an error
InactiveRocket.find('Falcon Heavy').print();
}
Start your Python web server and open the following link in your browser: http://localhost:8000/.