Why Template Class can't split template string when initializing?

Example:

function xTemplate(template){
  var a = template.split(Template.Pattern),
      l = a.length;
  return function(object){
    var x = a[0];
    for(var i=1;i<l;i+=4){
      x+= a[i]+String.interpret(object[a[i+2]])+a[i+3];
    }
    return x;
  };
}
var st = "<option value='#{index}' #{selected}>#{name}</option>",
     f = xTemplate(st),
     o = {index:1,name:'name'},
     t = new Template(st),
     now = function(){ return (new Date()).valueOf(); },
     xt = now()+500;
while(now()<xt);
var t1 = now();
for(var i=0;i<50000;i++){
  f(o);
}
var t2 = now();
for(var i=0;i<50000;i++){
  t.evaluate(o);
}
alert((now()-t2)/(t2-t1));

with xTemplate we can't use escape sequence and other, but
Template class can be rewritten...
Also String.prototype.split isn't cross-browser, when called with
RegExp as separator, so I used there fixed version from
 http://blog.stevenlevithan.com/archives/cross-browser-split .


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to