Skip to content Skip to sidebar Skip to footer

When Did All Browsers Start Supporting The String.replace(regexp, Replacement_function)?

According to the 6th Edition of JavaScript: The Definitive Guide (Flanagan, 2011): ECMAScript v3 specifies that the replacement argument to replace() may be a function instead of

Solution 1:

This answer is based on the comments to the question above (with special thanks to kangax, whose answer I will likely accept if he chooses to leave one!)

Whilst it's possible that I could have been reading "too many browsers" literally, it's also possible that String.replace() with a function as the argument was a problem in Safari 2.x (using JavaScriptCore) and in IEMac 5.x in the year 2005. Evidence of these problems in that time exists here, and with those particular versions of the aformentioned browsers here.

In fact the workaround mentioned by Gavin Kistner on the first of those pages is one whose performance may be better in some browsers than the functional replace method, as discussed here.

Nevertheless, performance aside, it seems (as I suspected) that a functional replace is acceptable in all browsers today.

Many thanks to all commenters on this question.

Post a Comment for "When Did All Browsers Start Supporting The String.replace(regexp, Replacement_function)?"