Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think what you want is to just make a function and pass it the values:

  const template = ({name}) => `hello ${name}`;
  const n1 = template({ name: 'joe' });
(Tagged templates won’t help here because the bit in curly braces is an expression which is evaluated to a value first; you’d need some kind of macro system to get access to the original variable name at runtime.)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: