title: Wait for fetch in different class
body: <p>I have two classes:</p>
  
  <p><strong>MazeGenerator.js</strong></p>
  
  <pre><code>constructor(gridsize) {
      this.fetchLevels(gridsize);
  }
  
  fetchLevels(gridsize){
      fetch("./data/hardcodedLevels.json")
          .then(data =&gt; data.json())
          .then(data =&gt; {
                  return data[gridsize-1];
              }
          ).then(grid =&gt; this.maakVeld(grid))
  }
  
  maakVeld(grid) {
      for (let i = 0; i &lt; grid[0].length; i++) {
          this.maze[i] = [];
          for (let j = 0; j &lt; grid[0].length; j++) {
              let wall = (grid[i][j] === 1);
              this.maze[i][j] = new Blok(j, i, wall);
          }
      }
  }
  
  returnMaze(){
      return this.maze;
  }
  </code></pre>
  
  <p>Which should return a two-dimensional array from a local json file. Grid.js should store this array and use it for further calculations.</p>
  
  <p><strong>Grid.js</strong></p>
  
  <pre><code>constructor(level) {
      this.generator = new MazeGenerator(level);
      this.veld = this.generator.returnMaze();
      this.grootte = this.veld.length;
  }
  </code></pre>
  
  <p>As it is now, <code>this.veld = this.generator.returnMaze();</code> is executed before the fetch has finished and gives an error because <code>this.veld</code> is undefined.
  Is there any way to wait untill the fetch has finished in another class?</p>