Javascript String tmpl(o)

Description

Javascript String tmpl(o)


String.prototype.tmpl = function(o) {
  return this.replace(/\{([^{}]*)\}/g, function(a, b) {
    var r = o[b];
    return typeof r === 'string' || typeof r === 'number' ? r : a;
  });/*from w ww.  ja  va  2 s.  c  om*/
};



PreviousNext

Related