Chrome控制台中为什么{} + {}不再是NaN? [英] Why is {} + {} no longer NaN in Chrome console?

查看:111
本文介绍了Chrome控制台中为什么{} + {}不再是NaN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我注意到,当您在控制台中输入 {} + {} 时,Chrome 49不再输出 NaN 。相反,它会输出字符串 [object Object] [object Object]



这是为什么? Chrome的devtools现在会自动换行以开头的所有内容{是否改变了语言?

$ c>,并以} 结尾于一对隐式括号中(查看代码),将其评估强制为一个表达式。这样, {} 现在创建一个空对象。如果你回顾历史(),你可以看到这一点,上一行将包含在(...)中。



为什么? 我不知道,但我可以猜到它减少了不知道block-vs-object-literal事件的新手的困惑,而且如果你只是想评估表达式。



事实上,这就是推理,正如 bug 499864 。纯粹的便利。并且因为节点REPL也有查看代码)。


I noticed today that Chrome 49 no longer outputs NaN when you type {}+{} into the console. Instead it outputs the string [object Object][object Object].

Why is this? Did the language change?

解决方案

Chrome devtools now automatically wrap everything that begins with { and ends with } in an implicit pair of parentheses (see code), to force its evaluation as an expression. That way, {} creates an empty object now. You can see this if you go back through the history (), the previous line will be contained in (…).

Why? I don't know, but I could guess it reduces confusion for newbies that don't know of the block-vs-object-literal thing, and it's also more helpful if you just want to evaluate an expression.

And in fact that's the reasoning, as discussed in bug 499864. Pure convenience. And because node REPL had it as well (see code).

这篇关于Chrome控制台中为什么{} + {}不再是NaN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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