How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 11-06-create-class-to-wrap-map.
  1. Create a main.js file that defines a new class named Rocket that takes a constructor argument name and assigns it to an instance property:
// main.js 
class Rocket { 
  constructor(name) { 
    this.name = name; 
  } 
   } 
  1. Create a class named RocketSiteMap file that creates a new map and assigns it as an instance property in the constructor:
// main.js 
class RocketSiteMap { 
  constructor () { 
    this.map = new Map(); 
     }    
   } 
  1. Add the set method that checks the type of the key and value arguments. This method should throw an error if the argument types are incorrect, otherwise set the pair as an entry on the map:

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.