Skip to content

Instantly share code, notes, and snippets.

@Kyle-Muir
Created November 5, 2015 22:06
Show Gist options
  • Save Kyle-Muir/bfb4b547f9a9df077d8f to your computer and use it in GitHub Desktop.
Save Kyle-Muir/bfb4b547f9a9df077d8f to your computer and use it in GitHub Desktop.
String.format for js
if (!String.format) {
String.format = function(format) {
var args = Array.prototype.slice.call(arguments, 1);
return format.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment