Javascript String interpolate(p)

Description

Javascript String interpolate(p)

String.prototype.interpolate = function(p) {
  const names = Object.keys(p);
  const vals = Object.values(p);
  return new Function(...names, `return \`${this}\`;`)(...vals);
}

// String.prototype.interpolate = function(p) {
//   return (p.charAt(0).toUpperCase() + word.slice(1));
// }/*from   ww w  .  ja v a2s.c o  m*/



PreviousNext

Related