If you have a function like:
function FunctionT(){
//do something
}
Would you refer to this as being empty or undefined or either works? Is there an official name for this?
A "noop" or "null function":
var noop = function(){}
In computer science, a NOP or NOOP (short for No Operation) [...] a command that effectively does nothing at all.
In computer science, a null function (or null operator) is subroutine that returns no data values and leaves the program state unchanged
Sources, http://en.wikipedia.org/wiki/NOP, https://en.wikipedia.org/wiki/Null_function
When I create such functions, I consider them "sentinel functions" - similar to identity functions in which the return value is either discarded or is a default a value (but not the identity); there should be no side-effects.
The terminology "sentinel function" is not common, but I find that the role they play is similar to that of sentinel values. (Although, one could argue that a function in JavaScript is a value and thus a "sentinel function" is a sentinel value..)
A related practice, used in slightly different circumstances, is to place some specific value at the end of the data, in order to avoid the need for an explicit test for termination in some processing loop, because the value will trigger termination by the tests already present for other reasons.
Rewriting this for a "sentinel function"
A related practice, used in slightly different circumstances, is use an empty function, in order to avoid the need for an explicit test for a function-object when invoking a function expression, because the sentinel function-object can be called.
For instance:
function doStuff(data, callback) {
callback = callback || function(){};
callback(compute(data));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With