Skip to content

Instantly share code, notes, and snippets.

@colthreepv
Created September 26, 2013 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colthreepv/6715230 to your computer and use it in GitHub Desktop.
Save colthreepv/6715230 to your computer and use it in GitHub Desktop.
sprint-like function for javascript
/**
* Thanks Raymond Powell
* http://stackoverflow.com/a/14640439/1071793
*/
String.prototype.format = function () {
var formatted = this,
prop,
regexp = new RegExp('\\{' + prop + '\\}', 'gi');
for (prop in arguments[0]) {
formatted = formatted.replace(regexp, arguments[0][prop]);
}
return formatted;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment