简体   繁体   English

chrome中针对不同实例的JavaScript函数返回结果有所不同

[英]Javascript function return result of a function differently in chrome for different instances

First i executed the below script in chrome console 首先,我在Chrome控制台中执行了以下脚本

 var x = 1; if (function f(){}) { x += typeof f; } x; 

I got '1undefined' as result. 结果为“ 1undefined”。

Then i executed function f(){} in console and again executed the above script,then i got the result '1function'. 然后,我在控制台中执行了函数f(){},并再次执行了上述脚本,然后得到了结果“ 1function”。 Now i opened another instance of chrome browser and again run the above script i am getting '1object'. 现在,我打开了chrome浏览器的另一个实例,然后再次运行上述脚本,我得到的是“ 1object”。

My question is why i am getting different result. 我的问题是为什么我得到不同的结果。

step1:- Run the above code snippet in chrome console. 步骤1:-在chrome控制台中运行上述代码段。 Result is 1undefined 结果是1未定义

step 2:-Run function f(){} in chrome console.Result is 1function 步骤2:在chrome控制台中运行函数f(){}。结果为1function

step 3:-open another instance of chrome and run the above snippet again.Result is 1object 第三步:打开另一个chrome实例并再次运行上面的代码片段。结果是1object

below that 1object ..i have this text 'Application Cache Checking event' 在该1object ..i下方具有此文本“应用程序缓存检查事件”

When you open another tab of chrome, it by defaults open Google home page. 当您打开Chrome的另一个标签时,默认情况下会打开Goog​​le主页。 If you execute the script there from console even for the first time, it will print 1object. 如果您是第一次从控制台执行脚本,它将打印1object。 As there is a javascript file on that page that define a variable F as object. 由于该页面上有一个javascript文件,该文件将变量F定义为对象。 You can check it here https://www.google.co.in/_/chrome/newtab?espv=2&ie=UTF-8 您可以在这里查看它https://www.google.co.in/_/chrome/newtab?espv=2&ie=UTF-8

As most sites minify js files, the variable are named A,B..... 由于大多数网站都会缩小js文件,因此该变量的名称为A,B .....

Its not magic :) 它不是魔术:)

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

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