Skip to content

Instantly share code, notes, and snippets.

@imyelo
Last active August 29, 2015 13:56
Show Gist options
  • Save imyelo/9087582 to your computer and use it in GitHub Desktop.
Save imyelo/9087582 to your computer and use it in GitHub Desktop.
String.prototype.format like python
(function (String) {
String.prototype.format = function (args) {
var copy = this + '';
var i, len;
for (i = 0, len = arguments.length; i < len; i++) {
copy = copy.replace(new RegExp("\\{" + i + "\\}", 'g'), String(arguments[i]));
}
return copy;
};
})(String);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment