Wikipedia's article on first-class citizens states that "some authors" believe functions are only first-class citizens in a language if the language supports their creation at run-time. This article written by James Coglan plainly calls functions first-class citizens - whether or not he is aware of the dispute over the criteria for first-class, I do not know.
Here are my questions:
It is worth mentioning that based upon more generalized criteria (applicable to other objects at-large), JavaScript functions are very obviously first-class citizens, namely they can be passed around as variables; therefore, I feel the criteria mentioned above adds an interesting dynamic - or, at least, a clarifying dynamic - to the conversation that is not - as one user writes - "arbitrary".
Functions can be created dynamically using the Function
constructor
var adder = new Function('a', 'b', 'return a + b');
adder(3, 4); // returns 7
More elaborately, this could be used to apply an arbitrary binary operator:
function make_binary_fun(operator) {
return new Function('a', 'b', 'return a ' + operator ' b');
}
var adder = make_binary_fun('+');
var multiplier = make_binary_fun('*');