匿名函数在JavaScript中是不好的做法吗? [英] Are anonymous functions a bad practice in JavaScript?
问题描述
我正在阅读在javascript中使用匿名函数是不好的做法,因为它可以使调试变得痛苦,但我还没有看到这个。 JavaScript中的匿名函数是否真的很糟糕,如果是这样,为什么?
I was reading that using anonymous functions in javascript is bad practice, because it can make debugging a pain, but I haven't seen this for myself. Are anonymous functions in JavaScript really bad practice and, if so, why?
推荐答案
不,匿名函数遍布整个网络的JavaScript中使用。它可能会使调试变得更加困难,但不足以说它们不应该被使用。
Nope, anonymous functions are used all over the place in JavaScript across the web. It may make debugging a little more difficult in spots, but not nearly enough to say that they shouldn't be used.
例如,JQuery广泛使用它们。
For example, JQuery makes extensive use of them.
有很多时候你想在正式声明的函数上使用它们,例如当你想限制它们的范围时。
There are a lot of times when you want to use them over formally declared functions, such as when you want to limit their scope.
这篇关于匿名函数在JavaScript中是不好的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!