Are there any differences between them?
In the development process, it seems that few people add an extra window. For example, the callback function parses strings in JSON format during Ajax.CopyCodeThe Code is as follows :...
Function callback (STR ){
VaR JSON = eval ('+ STR + ')');
}
...
Eval is usually used directly, rather than VaR JSON = Window. eval ('+ STR + ')');
For example, when alert is used for debugging, few users use window. Alert; in IE, they get the event object and use event. Few users use window. event. (In Firefox, event is also supported in some cases, but window. event is not supported. If you are interested, take a look at the whole family who obtained the event)
However, due to implementation differences between various engines, there are still some differences between them.Copy codeCode: var x = 5;
Function FN (){
VaR x = 'jack ';
Eval ('X = 10 ;');
}
FN ();
Alert (x); // --> 5
5 is output in all browsers. This indicates that after FN is called, Eval modifies the local variable X in FN, rather than the global variable X. That is, the closure environment of eval execution is in fn.
Change the eval of the above Code to window. Eval. After testing, we find that the performance of each browser is different.
IE6/7/8: 5 is output, that is, the global variable X is not modified, and the local variable X is modified.
Ie9/Firefox/Safari/Chrome/Opera: Output 10. The global variable X is modified.
We can draw a conclusion.
In IE6/7/8, Eval is the same as window. Eval. It is written in a UDF as a local closure; otherwise, it is a global closure.
In ie9/Firefox/Safari/Chrome/opera, Eval is the same as IE6/7/8, and window. Eval is a global Closure even if it is written in a custom function.
In addition, windows. .exe cscript in ieis always executed under global closures. It is surprising that Chrome also supports this method. Oh, Chrome is a standard, and IE is indispensable.