News for hackers. Stuff that matters.
Re:T.js - A tiny templating framework in ~400 bytes by jasonmoo on Monday August 13, 2012 @07:57PM (#4378754)
I like it. Here's a slightly more stable version. But still not crazy about using eval on arbitrary code. O.O

     function render(tpl,data){
          return tpl.replace(/{([^\}]+)}/g,function(_, key) {
              try { return eval("data."+key); }
              catch (e) { return ""; }
          });
     }
Re:T.js - A tiny templating framework in ~400 bytes by vain on Monday August 13, 2012 @08:04PM (#4378775)
the code i use in production doesn't use eval, but a recursive function. i like the anonymous function passed to replace, but think the catch destroys code beauty :)