Created
October 29, 2012 04:18
-
-
Save swijw/3971488 to your computer and use it in GitHub Desktop.
JavaScript String.format
This file contains hidden or 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
| String.format = function(src) { | |
| if (arguments.length) { | |
| return null; | |
| } | |
| var args = Array.prototype.slice.call(arguments, 1); | |
| return src.replace(/\{(\d+)\}/g, function(m, i) { | |
| return args[i]; | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment