Javascript: an in-depth understanding of basic Javascript knowledge

Source: Internet
Author: User

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 */


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.