blueimp/JavaScript-Templates

add with(o) statement for avoid o. object referrence

Opened this issue · 1 comments

this is my source code
...
var tmpl = function (str, data) {
var f = !/[^\w-.:]/.test(str) ? tmpl.cache[str] = tmpl.cache[str] ||
tmpl(tmpl.load(str)) :
new Function(
tmpl.arg + ',tmpl',
"var _e=tmpl.encode" + tmpl.helper + ";with("+tmpl.arg+") {_s='" +
str.replace(tmpl.regexp, tmpl.func) +
"';return _s;}"
);
//alert(f)
return data ? f(data, tmpl) : function (data) {
return f(data, tmpl);
};
};
...

add with("tmpl.arg") for avoid o. object referrence.

{%= o.title %} ===> {%= title %}

Not using the with statement is done on purpose to optimize performance.