2017-05-28 63 views
3

我在Chrome 58中遇到了new Function(...)的一些奇怪行爲。在調試點暫停時在開發人員控制檯中執行new Function(...)時,將返回undefined而不是一個新創建的功能。在調試模式下,新功能(...)在Chrome 58中返回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> 

這是瀏覽器的錯誤?

+1

是否正常'debugger'點作爲發生或者只有在執行'eval('debugger')'時? – Bergi

+0

正常的調試器使用情況也如此 –

+0

事實上,使用普通的調試器也是如此。我相應地更新了代碼,並且應該很容易在jsbin示例中試用它。 –

回答