Skip to content

Instantly share code, notes, and snippets.

@swijw
Created October 29, 2012 04:18
Show Gist options
  • Save swijw/3971488 to your computer and use it in GitHub Desktop.
Save swijw/3971488 to your computer and use it in GitHub Desktop.
JavaScript String.format
String.format = function(src) {
if (arguments.length) {
return null;
}
var args = Array.prototype.slice.call(arguments, 1);
return src.replace(/\{(\d+)\}/g, function(m, i) {
return args[i];
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment