eval() evaluates a string as a JavaScript expression within the current execution scope and can access local variables. new Function()parses the JavaScript code stored in a string into a function object, which can then be called. It cannot access local variables because the code runs in a separate scope. 从以上2点看出,eval的作用域是现行的作用域,而new Function是动态生成的,它的作用域始终都是window。并且,eval可以读到本地的变量,new Function则不能。 复制代码 代码如下: function test() { var a = 11; eval("(a = 22)"); //如果是new Function("return (a = 22);")(); a的值是不会覆盖的。 alert(a); // alerts 22 }