views:

38

answers:

3

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?

A: 

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.

Rob Lachlan
I mean, is there a name for a *single function* which does both?
nickf
+1  A: 

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.

Eli Bendersky
wouldn't it be possible in any language which allows either optional parameters (php, javascript, python, ruby ...), or function overloading (java...)?
nickf
Yes, as long as these languages have a way of distinguishing between "no parameter passed at all" and "parameter passed, but given the default value"
Eli Bendersky
+1  A: 

Some call it a property.

mkj
no, it's a function on an object, not a property of the object.
nickf