gpt4 book ai didi

function - Chrome - 评估 - 函数()

转载 作者:行者123 更新时间:2023-12-02 22:08:04 27 4
gpt4 key购买 nike

为什么 Chrome 会抛出异常

SyntaxError: Unexpected token (

当我尝试打电话时:

eval("function(){alert('test')}")

最佳答案

Chrome 抛出 SyntaxError 是因为你需要 () 围绕你的函数或者你需要命名它。

//This defines a as the function
eval("function a(){alert('foo')}");

//This returns the anonymous function
eval("(function(){alert('foo')})");

两者都应该可以正常工作。

关于function - Chrome - 评估 - 函数(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5979254/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com