简体   繁体   English

Chrome开发者工具控制台的异常行为

[英]strange behavior of Chrome Developer Tools Console

If you type in the console 如果您在控制台中输入

> new Object() 

Empty js object will appear in the console and it is expected, but if you type 空js对象将出现在控制台中,这是预期的,但是如果您键入

> {}

You get undefined undefined

It is strange. 它很奇怪。 Doesn't it ? 是不是

Calling a function with new always results in a value. new调用函数总会产生一个值。 Now, your second line, 现在,您的第二行,

{}

is an empty code block, not an object literal. 是一个空的代码块,而不是对象文字。

Try: 尝试:

({})

or: 要么:

0,{}

The console parses lines you type as statements , not expressions. 控制台将您键入的行解析为语句 ,而不是表达式。 An open curly brace at the start of a statement is a block delimiter, therefore, and not the start of an object literal. 因此,语句开始处的大括号是块定界符,而不是对象文字的开始。 By including other tokens to force the parser into parsing an expression, you can then begin an object literal. 通过包含其他标记来强制解析器解析表达式,然后可以开始对象文字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM