Skip to content

Instantly share code, notes, and snippets.

@dmiro
Last active December 17, 2015 00:09
Show Gist options
  • Select an option

  • Save dmiro/5518597 to your computer and use it in GitHub Desktop.

Select an option

Save dmiro/5518597 to your computer and use it in GitHub Desktop.
String format emulate
// Format emulate
String.prototype.format = function () {
var args = arguments;
return this.replace(/\{\{|\}\}|\{(\d+)\}/g, function (m, n) {
if (m == "{{") { return "{"; }
if (m == "}}") { return "}"; }
return args[n];
});
};
@dmiro

dmiro commented May 4, 2013

Copy link
Copy Markdown
Author

Example:

console.log("soy el numero {0}".format(1));
// return soy el numero 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment