I seem to be getting conflicting advice in the books I read on this functionality. I'm wondering if someone could clarify. For example Nicholas Zakas states the function argument has a signature of the format function(match, pos, originalText) (P139 : Pro JavaScript for Web Developers 2nd ed : Wrox)
He goes on to say When the regular expression has one match, the function gets passed three arguments (as above). When there are multiple capture groups, each matched string is passed in as an argument, with the last two positions being the position and originalText...
Then we come to Doug Crockfords, JavaScript: The Good Parts. (P90): He stipulates the syntax again as string(searcValue,replaceValue) searchValue can be a regex - great a match.. if replaceValue is a function, the first parameter is the matched text, then second is capture group 1, the third is capture group 2 and so on.. There is a noticeable difference here. (ie. No position argument)
I was also looking at an example in Pro JavaScript Design patterns (APress P152) that started this whole cross referencing process off. These guys (Ross Harmes/Dustin Diaz), rather unhelpfully specify the replaceValue function with two arguments named a & b. But it tends to reinforce the notion Doug Crockford describes.
Can someone confirm whether the Nicholas Zakas description is indeed a valid option too?