Javascript: an in-depth understanding of basic Javascript knowledge
The eval global function is shown in the loader of dojo as the next function.
Var eval _ = new Function ('Return eval (arguments [0]); '); // The Function runs in the top-level scope, but the running efficiency is slower, however, this method does not pollute global variables and calls the top-level scope eval ('var I = 100; '); alert (I ); // 100 eval _ ('var B = 100'); // alert (B); // error, B does not define var where = 'I am abroad '; // global scope where function test () {var where = ' '; // closure where eval _ ('alert (where )'); // I am abroad, global scope eval ('alert (where) '); // I am in China, partial full use of domain windows. eval ('alert (where) '); // I'm in IE6/7/8 abroad. I am in China and will not use a global scope. execScript} test () can be used ()
The kernal module of dojo also has an eval function. The code and explanation are as follows:
(Function ("d", "d. eval = function () {return d. global. eval? D. global. eval (arguments [0]): eval (arguments [0]);} ") (dojo);/* = dojo. eval = function (scriptText) {// try to execute the corner string (scriptText) in the global scope. Except for IE, other browsers can correctly execute this string in the global scope, execute dojo. eval ('var pi = 100'); alert (pi) // pi undefined; you need to execute the global variable dojo in IE. eval ("window. pi = 3.14 "); To execute global variables in IE, execScript can only be used, but it does not return a value and cannot terminate the execution */