title: What is the shortest possible way to write a block scope in JavaScript?
body: <p>Is this the shortest possible way to get a block scope in the body of the <code>for</code> loop?</p>
  
  <pre><code>x = {};
  for (i of ['a', 'b']) {
    (function(i) {
      x[i] = function() { this.v = i; }
    })(i);
  }
  </code></pre>
  
  <p>Or is there any syntactic sugar I am not able to find?</p>
  
  <p><em>Explanation:</em></p>
  
  <p>With block scope the created objects have different values.</p>
  
  <p><code>new x.a</code> ⟹ <code>x.(anonymous function) {v: "a"}</code><br>
  <code>new x.b</code> ⟹ <code>x.(anonymous function) {v: "b"}</code></p>
  
  <p>Without block scope</p>
  
  <pre><code>y = {};
  for (i of ['a', 'b']) {
    y[i] = function() { this.v = i; }
  }
  </code></pre>
  
  <p>the created objects will have the same value.</p>
  
  <p><code>new y.a</code> ⟹ <code>y.(anonymous function) {v: "b"}</code><br>
  <code>new y.b</code> ⟹ <code>y.(anonymous function) {v: "b"}</code></p>