Javascript String template(data)

Description

Javascript String template(data)


String.prototype._template = function (data) {
 var prop, result = this;
 data = data || {};//from   ww w .  j  av a2s  . co m
 for (prop in data) {
  if (data.hasOwnProperty(prop)) {
   result = result.replace('<%' + prop + '%>', data[prop]);
  }
 }
 return result.replace(/<%.+?%>/ig, '');
};



PreviousNext

Related