繁体   English   中英

在调试模式下,新函数(...)在Chrome 58中返回undefined

[英]new Function(…) returns undefined in Chrome 58 when in debug mode

我在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中的一个错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM