tagged template literal
function a() {
}
a(); // 보통은 이렇게 호출한다.
a``; // 이렇게 호출하는 방법도 있다.
// - 이는 tagged template literal 이라고 부른다.
// -------------
const person = 'Mike';
const age = 28;
function myTag (strings, personExp, ageExp) {
const str0 = strings[0]; // "That "
const str1 = strings[1]; // " is a "
const str2 = strings[2]; // "."
const ageStr = ageExp > 99 ? 'centenarian' : 'youngster';
return `${str0}${personExp}${str1}${ageStr}${str2}`;
}
const output = myTag`That ${person} is a ${age}`;
console.log(output); // That Mike is a youngster.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals