Last active
August 29, 2015 14:20
-
-
Save epitron/0683d45151dbdc3aa29b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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