Skip to content

Instantly share code, notes, and snippets.

@haingdc
Created February 28, 2018 11:07
Show Gist options
  • Save haingdc/74d971e7b08178cc5c43aab13db6307b to your computer and use it in GitHub Desktop.
Save haingdc/74d971e7b08178cc5c43aab13db6307b to your computer and use it in GitHub Desktop.
A Gentle Introduction to Functional JavaScript: Part 2
function t(s,o){
for(var p in o)
s=s.replace(new RegExp('{'+p+'}','g'), o[p]);
return s;
}
var data = { name: "July", age: "seventeen" };
t("When {name} was just {age}!", data);
// "When July was just seventeen!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment