“”.format() in JavaScript

Stumbled upon (again) string format() discussion. This time on stackoverflow.com.

Basic idea is right. But none of the implementations was optimized enough. At least for me. None of the answers presented had no obvious optimization of using enclosure to initialize once and store regular expressions, for subsequent usages. Also, none of the examples respected format() implementation if one already exists.

Here is my version. Optimized.

This version also seems to be very robust.

%d bloggers like this: