Javascript String templateFormat()

Description

Javascript String templateFormat()


String.prototype.templateFormat = function() {
  var args = arguments;
  return this.replace(/{(\d+)}/g, function(match, number) { 
    return typeof args[number] != 'undefined'
      ? args[number]/*  ww w .  j  a  v a 2 s .c  o m*/
      : match;
  });
};



PreviousNext

Related