Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
Created June 16, 2014 22:56
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 drgarcia1986/dab86626da5e20fbc81e to your computer and use it in GitHub Desktop.
Save drgarcia1986/dab86626da5e20fbc81e to your computer and use it in GitHub Desktop.
Habilitando método "Format" para JavaScript
String.prototype.format = function() {
var formatted = this;
for (var i = 0; i < arguments.length; i++) {
var regexp = new RegExp('\\{'+i+'\\}', 'gi');
formatted = formatted.replace(regexp, arguments[i]);
}
return formatted;
};
var txt = "Nome: {0} | Sobrenome: {1}".format("Diego", "Garcia");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment