Evalwith theWindow.evalthe Difference
Are there any differences between them?
Few people seem to add an extra windowin the development processand feel superfluous. such as The callback function in the Ajax process to parse the JSON format string
1 ... 2 function Callback (str) {3 var json = eval (' (' + str + ') '); 4 }5 ...
but because of the different engine implementation differences, they are different. Usually used directlyEval, rather thanvar json = window.eval (' (' + str + ') ');
Or, for example, when debuggingAlert, few people useWindow.alert;IEGets the event object using theEvent, few people usewindow.event. (Firefoxalso support in some casesEventand not supportwindow.event. )
1 var x = 5; 3 5 var x = ' Jack '; 7 eval (' x=10; '); 9 } 10 11 fn (); 12 13 alert (x); -->5
modified, put the above code Eval Replace Window.eval , the tests found that the performance was different in each browser. all the browsers output is 5, stating that after calling fn , eval modifies the fn The local variable xinside, not the global x. the closure environment that Eval executes is within FN.
IE6/7/8:still output5, that is, the global variable is not modifiedx, the modification is still a local variablex.
Ie9/firefox/safari/chrome/opera:OutputTen, the global variable is modifiedx.
Can come to a conclusion
in Ie6/7/8,likeeval and window.eval , writing within a custom function is a local closure, otherwise it is a global closure.
Ie9/firefox/safari/chrome/opera ,eval with the above ie6/7/8, Window.eval is a global closure even if it is written inside a custom function.
The difference between Eval and window.eval