Skip to content

Instantly share code, notes, and snippets.

@atzkey
Created December 13, 2010 15:58
Show Gist options
  • Save atzkey/739138 to your computer and use it in GitHub Desktop.
Save atzkey/739138 to your computer and use it in GitHub Desktop.
String.format extension for JavaScript
/*
String.format extension for JavaScript
Next line should give you an idea how to use it:
"{1}, {0}!".format("world", "Hello");
*/
String.prototype.format = function() {
var formatted = this;
for (arg in arguments) {
formatted = formatted.replace("{" + arg + "}", arguments[arg]);
}
return formatted;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment