title: ES6 Classes - Calling methods from a click event
body: <p>I am new to ECMA classes. </p>
  
  <p>In the following code, I have built a button class that is working fine. Now I am trying to call the prev_image() method from inside the click eventlistener. I know 'this' refers to the button instance but am not sure how to call a method from the Gallery class. Thanks for any help.</p>
  
  <pre><code>class Gallery{
  
      constructor(){
      }
  
      draw(){
  
          //build button
          prevbtn.draw();
  
          //button listener
          document.getElementById('prevbtn').addEventListener('click', function(){
              this.prev_image();   &lt;--- this errors out
              console.log('pressed'); &lt;--this works
          });
  
      }
  
      prev_image(){
          console.log('previous image!');
      }
  
  }
  </code></pre>