Created
June 2, 2014 19:53
-
-
Save zykadelic/9123d44f8a6169e622f2 to your computer and use it in GitHub Desktop.
Douglas Crockford's Supplant (http://javascript.crockford.com/remedial.html)
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
// Douglas Crockford's Supplant | |
if(!String.prototype.supplant){ | |
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