-
-
Save eerne/1092813 to your computer and use it in GitHub Desktop.
Add support for paths in String.substitute
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
/* | |
--- | |
... | |
*/ | |
String.implement({ | |
substitute: function(object, regexp){ | |
return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){ | |
if (match.charAt(0) == '\\') return match.slice(1); | |
return Object.getFromPath(object, name) || ''; | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment