title: Call function outside addEventListener method
body: <p>I have a JavaScript code that creates a 10x10 table, and when I click on a cell an addEventListener method prints the x,y cordinates and execute a function like below:</p>
  
  <pre><code>create_grid(name){
    var dim = 10;
    var my_field = document.createElement("table");
  
    for (var i = 0; i &lt; dim; i++) {
      var row = document.createElement("tr");
      for (var j = 0; j &lt; dim; j++) {
        var td = document.createElement("td");
        td.setAttribute("id", i + "," + j);
  
        td.addEventListener("click", function () {
          var obj = {
            x: this.id.split(",")[0],
            y: this.id.split(",")[1]
          };
  
          console.log("cell pressed: " + obj.x + "  " + obj.y);
        });
        row.appendChild(td);
      }
      my_field.appendChild(row);
    }
    document.getElementById(name).appendChild(my_field);
  }
  </code></pre>
  
  <p>I have another function like:</p>
  
  <pre><code>myFunction(x,y){
  
      // do something
  }
  </code></pre>
  
  <p>I would like to call myFunction inside the addEventListener of create_grid function:</p>
  
  <pre><code>td.addEventListener("click", function () {
          var obj = {
            x: this.id.split(",")[0],
            y: this.id.split(",")[1]
          };
  
          console.log("cell pressed: " + obj.x + "  " + obj.y);
  
  
          myFunction(obj.x, obj.y); // THIS DOESN'T WORK!
  });
  </code></pre>
  
  <p>The structure of the typescript file il this:</p>
  
  <pre><code>export class gameComponent {
  
        create_grid(name){
            // code
        }
  
        myFunction(x,y){
           // code 
        }
  
  }
  </code></pre>