开发者

What do you call functions which get and set?

开发者 https://www.devze.com 2022-12-25 23:41 出处:网络
The jQuery framework has a lot of functions which will either retrieve or mutate values depending on the parameters passed:

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?


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.


Is there a standard name for functions which behave like this?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号