title: Access a nested variable from nested function
body: <pre><code> &lt;script&gt;
          const counter ={
              cnt: 0,
              inc: function(){
                  cnt++;
                  console.log(cnt);
              }        
          }
          const button = document.getElementsByTagName('button')[0];
          button.addEventListener('click', counter.inc, false);
  
      &lt;/script&gt;
  </code></pre>
  <p>If I run this code as is, I'll get an error of an undefined variable. So I can fix this by adding <code>couner.cnt</code> inside of function. However, I don't want to do this. Is there any other way?</p>