匿名函数在 JavaScript 中是一种不好的做法吗? [英] Are anonymous functions a bad practice in JavaScript?

查看:28
本文介绍了匿名函数在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆