Created
December 12, 2010 23:36
-
-
Save sebmarkbage/738466 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
| String.implement({ | |
| substitute: function(object, regexp){ | |
| return this.replace(regexp || (/\\?\{([^{}:]+)(?::([^{}:]+))?\}/g), function(match, name, format){ | |
| if (match.charAt(0) == '\\') return match.slice(1); | |
| var value = (object[name] != null) ? object[name] : ''; | |
| if (format && typeof value.format == 'function') value = value.format(format); | |
| return value; | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment