admin管理员组文章数量:1326328
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?
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?
Share Improve this question edited Jul 11, 2015 at 16:07 Alex Saskevich asked Jul 11, 2015 at 16:00 Alex SaskevichAlex Saskevich 3511 gold badge3 silver badges13 bronze badges 2- I do like how you called it a feature and not a bug – Dan Commented Jul 11, 2015 at 16:03
- 1 I wrote a little article about it: medium./@asaskevich/… – Alex Saskevich Commented Jul 15, 2015 at 11:10
2 Answers
Reset to default 7This is the way chrome evaluates your input:
with (typeof __mandLineAPI !== 'undefined' ? __mandLineAPI : { __proto__: null }) {
// your code here...
}
So once your input is }{
it bees
with (typeof __mandLineAPI !== 'undefined' ? __mandLineAPI : { __proto__: null }) {}{} // indefined
Next input }-+{
bees
undefined -+ {} // NaN
And so on.
This happens because Chrome wraps the code you enter in the console in the following construction:
with (typeof __mandLineAPI !== 'undefined' ? __mandLineAPI : { __proto__: null }) {
// Your code
}
So, when you enter something like } 10 {
, the code evaluates to:
with (typeof __mandLineAPI !== 'undefined' ? __mandLineAPI : { __proto__: null }) {
} 10 {
}
which is empty with
block, a number, and empty structural block.
__mandLineAPI
is the internal object that contains Chrome Command Line API.
本文标签: Strange behaviour of JavaScript in Chrome Developer ToolStack Overflow
版权声明:本文标题:Strange behaviour of JavaScript in Chrome Developer Tool - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742202846a2432279.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论