title: Uncaught TypeError: keyHandler is not a function
body: <p>I'm building an MVC style javascript game and I've run into a problem. I need to check if the keyState is 39 before calling a function, but I'm getting the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Uncaught TypeError: _self.keyHandler is not a function
  </code></pre>
  
  <p>Can anybody help me? The problem is with the following piece of code:</p>
  
  <pre><code>    if(keyState[39] = true){
          _self.keyHandler();
      };
  </code></pre>
  
  <p>FULL CODE:</p>
  
  <pre><code>GOBLINS.Controller.prototype.input = function() {
  
          var _self = this;
          var keyState = {};
  
      window.addEventListener('keydown', function(e){
          if(e.keyCode === 39){ // Move Right
              keyState[e.keyCode] = true; 
          };
          if(e.keyCode === 37){ // Move Left
              keyState[e.keyCode] = true; 
          };
          if(e.keyCode === 38){ // Move Up
              keyState[e.keyCode] = true; 
          };
          if(e.keyCode === 40){ // Move Down
              keyState[e.keyCode] = true; 
          };
      }, true);
  
      window.addEventListener('keyup', function(e){
          if(e.keyCode == 39){
              keyState[e.keyCode] = false; 
          };
          if(e.keyCode == 37){
              keyState[e.keyCode] = false; 
          };
          if(e.keyCode == 38){
              keyState[e.keyCode] = false; 
          };
          if(e.keyCode == 40){
              keyState[e.keyCode] = false; 
          };
      }, true);
  
          if(keyState[39] = true){
              _self.keyHandler();
          };
  
      this.keyHandler = function(){
          if(keyState[39] === true){
              this.M.images[2].moveRight();
              console.log(this.M.images[2]);
              };
          if(keyState[37] === true){
              this.M.images[2].moveLeft();
              };
          if(keyState[38] === true){
              this.M.images[2].moveUp();
              };
          if(keyState[40] === true){
              this.M.images[2].moveDown();
          };
      };
  
      window.requestAnimationFrame(function(){
          _self.input();
      });
  };
  </code></pre>