We all love JS, don't we? Yes, we do. But, unfortunately, JS does not allow us to insert variables inside a string. We must close our quotes, concatenate with a + operator, and live our lives. What this tiny script does is replace anything inside #{ } for a variable. Ruby users know what this is.
Let's say, you have two variables:
var mood = "nice";
var person = "Bob";
And this is the string you want to format:
var myString = "This is #{mood}, isn't it, #{person}?";
You would simply do a:
myString.pretify();
And this is your result:
"This is nice, isn't it, Bob?"
I find it pretty fast-forward, and useful :)
@endel I think eval is the right thing here. You should be able to put any expression that returns something to interpolate. And function calls are expressions (even when returning undefined), but that's up to the programmer.
So it's more like: eval is dangerous, programmers are evil. :)