问题描述
输入Chrome js控制台后输入以下代码我感到很惊讶:
I am surprised that the following code when input into the Chrome js console:
{} instanceof Object
导致此错误消息:
任何人都可以告诉我为什么会这样以及如何修复它?
Can anyone please tell me why that is and how to fix it?
推荐答案
instanceof 的语法是:
RelationalExpression instanceof ShiftExpression
每。
语句开头的标点符号 {
被视为块的开头,因此以下}
关闭块并结束语句。
The punctuator {
at the start of a statement is seen as the start of a block, so the following }
closes the block and ends the statement.
以下 instanceof
运算符是下一个语句的开头,但它不能在s因为它必须以 RelationalExpression 开头,所以解析器会出现意外。
The following instanceof
operator is the start of the next statement, but it can't be at the start because it must be preceded by a RelationalExpression, so the parser gets a surprise.
你需要强制 {通过在语句的开头添加其他内容来将
视为对象文字,例如
You need to force {}
to be seen as an object literal by putting something else at the start of the statement, e.g.
({}) instanceof Object
这篇关于未捕获的SyntaxError:意外的令牌实例(使用Chrome Javascript控制台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!