I know in PHP we can do something like this:
$hello = \"foo\"; $my_string = \"I pity the $hello\";
Output: \"I pity the foo\"<
\"I pity the foo\"
String.prototype.interpole = function () { var c=0, txt=this; while (txt.search(/{var}/g) > 0){ txt = txt.replace(/{var}/, arguments[c]); c++; } return txt; }
Uso:
var hello = "foo"; var my_string = "I pity the {var}".interpole(hello); //resultado "I pity the foo"