Firefox和Node.js之间的解释差异 [英] Difference in interpretation between Firefox and Node.js

查看:117
本文介绍了Firefox和Node.js之间的解释差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了Firefox和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆