获取和设置的函数叫什么?
jQuery 框架有很多函数,这些函数将根据传递的参数检索或改变值:
$(this).html(); // get the html
$(this).html('blah'); // set the html
对于像这样运行的函数有标准名称吗?
The jQuery framework has a lot of functions which will either retrieve or mutate values depending on the parameters passed:
$(this).html(); // get the html
$(this).html('blah'); // set the html
Is there a standard name for functions which behave like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AFAIK,对于同时充当 getter 和 setter 的单个函数来说,没有“标准”名称。这是一个不太常用的习惯用法,但在某些语言中是可能的,而且只要有充分的记录,使用它就没有坏处。
AFAIK, there is no "standard" name for a single function that acts both as a getter and as a setter. It's an idiom not very commonly used, but it's possible in some languages, and as long as it's well documented, there's no harm in using it.
有些人称之为财产。
Some call it a property.
Getter 和 Setter。
编辑:
我刚刚意识到您需要一个函数来执行此操作。用技术术语来说这是一个坏主意。除非您的语言提供属性,否则尝试设置单个函数来执行此操作是非常不可读的。
Getters and Setters.
EDIT:
I just realized that you want a single function to do this. The technical term for this is a bad idea. Unless your language provides properties, trying to rig up a single function to do this is very unreadable.