切换功能的用处 [英] Usefulness of Toggle functions

查看:150
本文介绍了切换功能的用处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



还是写'Toggle'类型的函数会更好一些(更好的是写一些明确做某事的函数(例如HideForm / ShowForm等等)即ToggleVisibility)?

我发现切换类型函数awkard是因为很难通过读取代码来跟踪状态。



在什么情况下切换类型函数有用?

解决方案

来处理按钮(像复选框一样)和可见性,但大多数情况下我会避免它,因为它会让你更难以控制想要处理的想法。



如果你不能或不能确定初始状态(但通常你可以)。无论如何,大多数情况下不需要一些'simetric'或简单的代码来运行,所以我不会为.toogle做很多事情。


Is it better to write functions that explicitly do something (i.e. HideForm/ShowForm etc...)

or is it better to write 'Toggle' type functions (i.e. ToggleVisibility)?

I find Toggle type functions awkard because it's hard to track the state by reading the code.

In what situations is a toggle type function useful?

解决方案

I use it sometimes in JavasScript to handle buttons( checkbox like ) and visibility, but mostly I avoid it, because it makes a little harder to control the state of the think you are trying to handle.

It can be bad if you are not or can't be sure of the initial state (but usually you can). Anyway, most of the cases require not some 'simetric' or simple code to be run, so I don't go for .toogle a lot

这篇关于切换功能的用处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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