title: In python, can I create a closure with an anonymous function?
body: <p>Out of curiosity, I'd like to see if there's a better answer than what's below.
  How can I convert this:</p>
  <pre><code>def counter():
      ctr = 0
      def inner():
          ctr += 1
          return ctr
      return inner
  counter = counter()
  </code></pre>
  <p>into this javascript equivalent?</p>
  <pre><code>counter = (function() {
      let ctr = 0;
      return function() {
          return ++ctr;
      } //inner anonymous func
  })(); //outer func, called and forgotten, sort of.
  </code></pre>
  <p>The python above is fine, I was just curious if there was a faster/more readable way to do this.</p>
  <p>To be clear, I don't want the outer factory function to be available after its called, and I want it to be called as soon as its defined. Think of it as a closure singleton.
  Thanks!</p>