The string value to search and replace within.
The value to search for. Can be a string, a global RegExp, or any object
with a [Symbol.replace] method.
The replacement string (may use the $&, $1…$n and $' patterns, or $ followed by a
backtick for the text before the match)
or a replacer function called once per match.
A new string with every occurrence of searchValue replaced by replaceValue.
Polyfill implementation of
String.prototype.replaceAll()that returns a new string with all matches of a pattern replaced by a replacement.Matches the behaviour of the native
String.prototype.replaceAll()method:searchValue(identified like the native IsRegExp, so aRegExpwhoseSymbol.matchis falsy isn't one and an object whoseSymbol.matchis truthy is) must have a global (g) flag in itsflags; a non-global one throws aTypeError.searchValueis treated as a literal pattern (special regex characters are escaped) and all occurrences are replaced. Like the native function the value and thesearchValueare converted to strings (aSymbolthrows aTypeError).searchValuehas a[Symbol.replace](read once, a value which isn'tnull,undefinedor a function throws aTypeError), it is called with the (unconverted) value andreplaceValue, like the native function. On a runtime without a nativeSymbol(eg. IE) the method for the polyfill symbol (getKnownSymbol(WellKnownSymbols.replace)) is called, and on a runtime withoutSymbol.replaceaRegExpis used like its native[Symbol.replace].replaceValueis a function it is invoked for each match with the matched substring, captured groups, the match index, and the original string.