How to do it...

  1. Open your command line application and navigate to your workspace.
  2. Create a new folder named 08-04-checking-with-instanceof.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create two objects rocketMap and inactiveRocketMap:
// main.js 
let rocketMap = {};  
let inactiveRocketMap = {}; 
  1. Define a new class named Rocket. Add a constructor. Use the name to assign the instance to the rocketMap and define a simple print method:
// main.js 
class Rocket { 
  constructor(name) { 
    this.name = name; 
    rocketMap[name] = this; 
     } 
  print() { 
    console.log(this.name + ' is a rocket'); 
  } 
}  
  1. Add a static find method that retrieves an instance from the rocketMap:
// main.js class Rocket { static find (name) { return ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.