Skip to content

Instantly share code, notes, and snippets.

@zykadelic
Created June 2, 2014 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zykadelic/9123d44f8a6169e622f2 to your computer and use it in GitHub Desktop.
Save zykadelic/9123d44f8a6169e622f2 to your computer and use it in GitHub Desktop.
Douglas Crockford's Supplant (http://javascript.crockford.com/remedial.html)
// 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