Chrome开发者工具中JavaScript的奇怪行为 [英] Strange behaviour of JavaScript in Chrome Developer Tool

查看:109
本文介绍了Chrome开发者工具中JavaScript的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,在Developer Tool中使用JavaScript,我发现了一个奇怪的特性。 Chrome接受开放括号与运算符(加号,减号)和运算符与右括号之间的任何代码并执行它,如下所示:

我没有在其他浏览器中发现这种行为,只是在Chrome中。

也许这是一个功能,但为什么以及它如何工作,它可能是JavaScript引擎的问题吗?

解决方案

这是chrome评估输入的方式:

  with(typeof __commandLineAPI!== 'undefined'?__commandLineAPI:{__proto__:null}){
//您的代码在这里...
}

因此,一旦您的输入为} {
,它就会变成

  with(typeof __commandLineAPI!=='undefined'?__commandLineAPI:{__proto__:null}){} {} // indefined 

下一个输入} - + {
变成

  undefined  -  + {} // NaN 

等等。


Recently, working with JavaScript in Developer Tool, I found strange feature. Chrome accepts any code between opening bracket with operator (plus, minus sign) and operator with closing brackets and executes it, like this:

I didn't find this behaviour in another browsers, just in Chrome.

Maybe it's a feature, but why and how it works, can it be problem with JavaScript engine?

解决方案

This is the way chrome evaluates your input:

with (typeof __commandLineAPI !== 'undefined' ? __commandLineAPI : { __proto__: null }) {
 // your code here...
}

So once your input is }{ it becomes

with (typeof __commandLineAPI !== 'undefined' ? __commandLineAPI : { __proto__: null }) {}{} // indefined

Next input }-+{ becomes

undefined -+ {} // NaN

And so on.

这篇关于Chrome开发者工具中JavaScript的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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