Closed Bug 1331367 Opened 8 years ago Closed 8 years ago

closure scope error for let in for-of loop

Categories

(Firefox :: Untriaged, defect)

50 Branch
All
Unspecified
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 449811

People

(Reporter: email.james.macdonald, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0 Build ID: 20161208153507 Steps to reproduce: When I run the following JavaScript code: let funcs = [] for(let x of [1,2,3]) { funcs[x] = function(){ console.log("test:", x) } } funcs[1]() //test: 1 funcs[2]() //test: 2 funcs[3]() //test: 3 which is consistent with the following link: https://shadtechblog.wordpress.com/2016/04/12/how-does-es6-let-solve-closure-scope-problem/ about a third of the way down at "Block Scope with let" Actual results: the console prints: test: 3 test: 3 test: 3 Expected results: the console should have printed: test: 1 test: 2 test: 3
Hardware: Unspecified → All
Summary: JavaScript printing wrong values to the console → closure scope error for let in for-of loop
it's fixed in firefox 51.
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.