Last active
December 17, 2015 00:09
-
-
Save dmiro/5518597 to your computer and use it in GitHub Desktop.
String format emulate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
console.log("soy el numero {0}".format(1));
// return soy el numero 1