News for hackers. Stuff that matters.
Re:T.js - A tiny templating framework in ~400 bytes by Kilimanjaro on Monday August 13, 2012 @09:53PM (#4379015)
I use this little helper in my underground lab:

    function template(str,data){
        for(var i in data){
            str=str.replace(new RegExp("{("+i+")}","g"),data[i])
        }
        return str
    }
It can be used with arrays and object literals as well:

    txt = template('hello {name}!',{name:'Jen'})

    txt = template('days: {0}, {1} and {2}',['mon','tue','wed'])
GPL and WTFPL just in case.

* Looks coincidentally similar to Fuchs'

Re:T.js - A tiny templating framework in ~400 bytes by VMG on Tuesday August 14, 2012 @05:21AM (#4380046)
Watch out for

    for (var prop in obj) {}
It may iterate over attributes defined in the objects prototype. The right way to iterate over an object is

    for(var prop in obj) {
        if(obj.hasOwnProperty(prop))
            doSomethingWith(obj[prop]);
    }
(see http://stackoverflow.com/a/588276)
Re:T.js - A tiny templating framework in ~400 bytes by drgath on Tuesday August 14, 2012 @08:17AM (#4380490)
While true, 'data' should always just be an object-literal. If template() is ever passed an instance of an object, there's something else seriously wrong elsewhere in your script.
Re:T.js - A tiny templating framework in ~400 bytes by thezilch on Monday August 13, 2012 @10:48PM (#4379155)