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 argume
Zakas is correct, the penultimate and final arguments are pos and originalText. From the ECMA-262 3rd and 5th editions (section 15.5.4.11):
If
replaceValueis a function, then for each matched substring, call the function with the following m + 3 arguments. Argument 1 is the substring that matched. IfsearchValueis a regular expression, the next m arguments are all of the captures in the MatchResult (see 15.10.2.1). Argument m + 2 is the offset within string where the match occurred, and argument m + 3 isstring.
Note that String.prototype.replace was new in ECMA-262 3rd edition. MSDN documentation for JScript and MDC documentation for JavaScript both conform to this specification.