Created
March 21, 2014 13:44
-
-
Save james2doyle/9686574 to your computer and use it in GitHub Desktop.
String.prototype.supplant from Douglas Crockford's Remedial JavaScript
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.prototype.supplant = function(o) { | |
return this.replace(/{([^{}]*)}/g,function(a, b) { | |
var r = o[b]; | |
return typeof r === 'string' || typeof r === 'number' ? r : a; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment