Skip to content

Instantly share code, notes, and snippets.

@furf
Created May 1, 2009 18:42
Show Gist options
  • Save furf/105176 to your computer and use it in GitHub Desktop.
Save furf/105176 to your computer and use it in GitHub Desktop.
var template = function(str, obj) {
return str.replace(/\$\{([^}]+)\}/g, function(match, prop) {
return (prop in obj) ? obj[prop] : match;
});
};
var str = template('${greeting}, ${noun}.', {greeting:'Ciao',noun:'mondo'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment