Created
March 29, 2011 13:51
-
-
Save mpenet/892394 to your computer and use it in GitHub Desktop.
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
jQuery.format = function(s, args) { | |
return s.replace(/\{([^}]+)\}/g, function(_, match){return args[match] || '';}); | |
}; | |
>> $.format('Hello {world}, {again}', {world: "universe", again: "testing"}); | |
"Hello universe, testing" | |
>> $.format('Hello {0}, {1}', ["foo", "bar"]); | |
"Hello foo, bar" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment