I agree. I would think replaceAll would behave like the following:
/* Usage:
> 'abcdefabc'.replaceAll('abc')
'def'
> 'abcdefabc'.replaceAll('abc', '+')
'+def+'
> 'abcdefabc'.replaceAll(/abc/, '+')
'+def+'
> 'abcdefabc'.replaceAll(/abc/g, '+')
'+def+'
*/
String.prototype.replaceAll = function (re_or_str, sub) {
return this.split(re_or_str).join(sub||'')
}
On a side note, is it just me or does the linked polyfill for String.prototype.replaceAll [1] seem wildly complex???[1] https://github.com/es-shims/String.prototype.replaceAll/blob...