Skip to content

Instantly share code, notes, and snippets.

@epitron
Last active August 29, 2015 14:20
Show Gist options
  • Save epitron/0683d45151dbdc3aa29b to your computer and use it in GitHub Desktop.
Save epitron/0683d45151dbdc3aa29b to your computer and use it in GitHub Desktop.
String.prototype.interp = function() {
var matcher = /#{(.+?)}/g
var replacer = function(_, expr) {
return eval(expr)
}
return this.replace(matcher, replacer)
}
// Example:
var name = "Bob"
var age = 20
console.log("Your name is #{name}, and you are #{age} years old! (You were born in #{new Date().getFullYear() - age}!)".interp())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment