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.
* Looks coincidentally similar to Fuchs'