Edit: Nevermind, you don't really need Closure for this. See Esailija's answer.
There is another option, if you happen to be using the Closure library. First you have to rewrite doOpSingle2 so that the flag is first:
function doOpSingle2(flag, arrelem)
{
// do something with one array element
}
then you can do
var y = A.map(goog.partial(doOpSingle2, theFlag));
goog.partial partially applies the function, so goog.partial(doOpSingle2, theFlag)
is equivalent to this function:
function(arrElem) {
return doOpSingle2(theFlag, arrElem);
}
In this particular case, I probably wouldn't recommend this approach, but there might be similar situations where it works well.