Firefox和Node.js之间的解释差异 [英] Difference in interpretation between Firefox and Node.js
问题描述
'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)输出
right
right
而Node.js(6.4。 0)输出
left
right
都在Ubuntu 14.04上。我没有可能用其他ECMAScript引擎进行测试。
任何想法有什么区别的原因,哪些实现对规范是正确的?
您的Node版本正确, let
code> for loop应该有块范围。
FF 48 根本不支持for / in-in循环遍历范围,它似乎用FF 51修复。
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?
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.
这篇关于Firefox和Node.js之间的解释差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!