Firefox 7 中的 Javascript 匿名函数
更新到 Firefox 7 后,我收到以下错误:
函数语句需要名称
这个特定的函数被定义为
fun = eval("function (item) { //Function body }");
如果我将其重写为:
fun = eval("function view(item) { //Function body }");
错误不再显示,但程序仍然无法运行。
Ps.-我知道评估字符串不是一个好主意。这是一个我必须修复的遗留应用程序,其中一些函数是按需从数据库作为字符串下载的。
After updating to Firefox 7, I am getting the following error:
function statement requires a name
This particular functions is defined as
fun = eval("function (item) { //Function body }");
If I rewrite it as:
fun = eval("function view(item) { //Function body }");
The error does not show up any more, but the program still does not work.
Ps.- I know that evaluating a string is not a good idea. This is a legacy application that I have to fix in which some functions are downloaded from a database as strings on demand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将其括在括号中
但这没有意义,因为它什么也没做。也许你想要:
或者
Wrap it in brackets
But that doesn't make sense as it does nothing. Maybe you want:
Or
函数声明(就是您所拥有的)需要规范的标识符。
就像 ES 规范不允许的那样(即使某些浏览器可能允许)。只有函数表达式可以是匿名的。
A function declaration (is what you've got there) requires an identifier by spec.
just like that is not allowed by ES specification (even if some browsers might allow it anyway). Only function expression may be anonymous.
只是一个猜测,也许可以尝试:(
我刚刚添加了 return 语句)
just a guess, maybe try with:
(I just added the return statement)
如果函数被定义为字符串并且您希望使用它而不是每次都调用 eval,您可以这样做:
或者只是
if the function is defined as a string and you wish to use it without calling eval everytime, you could do this:
Or just