eric d. Hi, thanks for that brilliant article. Made a lot of things a lot clearer! Note: new RegExp("%([1-" + arguments.length + "])", "g"); will fail passed 9 arguments (the regexp would be "%([1-10])" so it will only match %0 and %1).
I think an easy fix would be something like: function format(string) { var args = arguments; var pattern = new RegExp("%([0-9]+)", "g"); return String(string).replace(pattern, function(match, index) { if (index == 0 || index >= args.length) throw "Invalid index in format string"; return args[index]; }); }; (Sorry for nitpicking, I understand it was only an example and brevety is the main objective, but its a great function to have)