String.replace's second parameter, the replacement string, uses $ as a special character for submatches of RegExp patterns. Per MDN's documentation on replace:
"The replacement string can include the following special replacement patterns...$n Where n is a non-negative integer lesser than 100, inserts the nth parenthesized submatch string, provided the first argument was a RegExp object."
By specifying a function (anonymous or otherwise) as the second parameter, we separate out submatches as function parameters and thus avoid the need for using $$ instead of $ in templates.
Addresses #43
String.replace
's second parameter, the replacement string, uses$
as a special character for submatches of RegExp patterns. Per MDN's documentation onreplace
:By specifying a function (anonymous or otherwise) as the second parameter, we separate out submatches as function parameters and thus avoid the need for using
$$
instead of$
in templates.