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 :)
Wouldn't this be better if passing an object as argument ? (also
eval
makes you pass globals, which is not good at all)If you are interested, I builded a little more flexible one : http://mlb.tl/LGDK
Cheers