Skip to content

Instantly share code, notes, and snippets.

@niyazpk
Created December 11, 2011 18:08
Show Gist options
  • Save niyazpk/1461856 to your computer and use it in GitHub Desktop.
Save niyazpk/1461856 to your computer and use it in GitHub Desktop.
// Templates:
param = { media: 'http://media.valvion.com/' };
url = "{media}logo.gif".supplant(param);
// Unfortunately, supplant method is not there in ES5 spec,
// so use the below prototype:
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