Skip to content

Instantly share code, notes, and snippets.

@andrewthauer
Created March 7, 2014 14:22
Show Gist options
  • Save andrewthauer/9412339 to your computer and use it in GitHub Desktop.
Save andrewthauer/9412339 to your computer and use it in GitHub Desktop.
// Extend the String type to include a format method
String.prototype.format = function (format, args) {
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i + 1]);
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment