创业经验
带标签的模板
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Template_literals#%E5%B8%A6%E6%A0%87%E7%AD%BE%E7%9A%84%E6%A8%A1%E6%9D%BF
适合处理固定变量要加判断的格式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| const person = "Mike"; const age = 28;
function myTag(strings, personExp, ageExp) { const str0 = strings[0]; const str1 = strings[1]; 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);
|
最后更新时间: