head-let-fresh-binding-per-iteration.js (973B)
1 // Copyright (C) 2011 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-runtime-semantics-forin-div-ofbodyevaluation-lhs-stmt-iterator-lhskind-labelset 5 es6id: 13.7.5.13 6 description: > 7 let ForDeclaration: creates a fresh binding per iteration 8 ---*/ 9 10 var fns = {}; 11 var obj = Object.create(null); 12 obj.a = 1; 13 obj.b = 1; 14 obj.c = 1; 15 16 for (let x in obj) { 17 // Store function objects as properties of an object so that their return 18 // value may be verified regardless of the for-in statement's enumeration 19 // order. 20 fns[x] = function() { return x; }; 21 } 22 23 assert.sameValue(typeof fns.a, 'function', 'property definition: "a"'); 24 assert.sameValue(fns.a(), 'a'); 25 assert.sameValue(typeof fns.b, 'function', 'property definition: "b"'); 26 assert.sameValue(fns.b(), 'b'); 27 assert.sameValue(typeof fns.c, 'function', 'property definition: "c"'); 28 assert.sameValue(fns.c(), 'c'); 29 30 reportCompare(0, 0);