Javascript String substitute(object, regexp)

Description

Javascript String substitute(object, regexp)


(function(String){

if (String.prototype.substitute) {
 return;/*from w  w  w .  j a v  a 2 s.c  o  m*/
}

String.prototype.substitute = function(object, regexp){
 return String(this).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
  if (match.charAt(0) == '\\') return match.slice(1);
  return (object[name] !== null) ? object[name] : '';
 });
};

})(String);



PreviousNext

Related