javascript - new Function(...) 在 Debug模式下在 Chrome 58 中返回 undefined

标签 javascript function google-chrome debugging

我在 Chrome 58 中遇到了 new Function(...) 的一些奇怪行为。当暂停时在开发人员控制台中执行 new Function(...)在调试点,返回 undefined 而不是新创建的函数。

jsbin 示例:http://jsbin.com/raluwu/edit?html,output

<!DOCTYPE html>
<html>
<body>
  <script>
    // open the developer console in Chrome 58, 
    // and run this code until the debug point
    debugger;
    //eval('debugger');
    // when at the debug point, enter the following in the console:
    //
    //     var f = new Function ('a', 'return a + a');
    //     // f should be a function but is undefined when in debug mode
    // 
    //     console.log(f(2));   
    //     // should return 4, but throws "Uncaught TypeError: f is not a function"

    // without debug point, everything runs fine:
    var f = new Function ('a', 'return a + a');
    console.log(f(2)); // 4
  </script>
</body>
</html>

这是 Chrome 中的错误吗?

最佳答案

我做了更多的挖掘并找到了关于这个问题的错误报告:

https://bugs.chromium.org/p/chromium/issues/detail?id=705149

所以,这确实是 Chrome 中的一个错误

关于javascript - new Function(...) 在 Debug模式下在 Chrome 58 中返回 undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44228320/

相关文章:

javascript - Mocha js 调用 After() 太快了吗?

javascript - 在 PHP 中为 Javascript 生成小而有效的变量名的算法

php - php将数组插入mysql数据库

javascript - 函数声明比函数表达式快?

HTML5 视频色差 Chrome 和 Internet Explorer

jquery - 从Chrome的日期类型输入中删除占位符

javascript/jquery 根据输入到文本输入字段中的值更改 html 元素

javascript - 在 JavaScript 中从 Base64 字符串创建 BLOB

javascript - jquery 在鼠标悬停时淡入淡出

node.js - 如何打开 chrome 浏览器到 chrome 开发工具 url