Reputation:
I have come across an anomaly between Firefox and Node.js. Given the following code:
'use strict';
const obj = {};
for (let f of ['left', 'right']) {
obj[f] = function() {
return f;
};
}
console.log(obj.left());
console.log(obj.right());
Firefox (48.0) outputs
right
right
while Node.js (6.4.0) outputs
left
right
Both on Ubuntu 14.04. I didn't have the possibility to test with other ECMAScript engines.
Any idea what is the reason for the difference, and which implementation is correct with respect to the specification?
Upvotes: 0
Views: 61
Reputation: 665316
Your version of Node is correct here, let
in a for
loop should have block scope.
FF 48 simply doesn't support "for/for-in loop iteration scope" yet, it appears to be fixed with FF 51.
Upvotes: 1