function highlight(strings, ...values) {
let str = '';
strings.forEach((string, i) => {
str += `${string} ${values[i] || ''}`;
});
return str;
}
const name = 'Snickers';
const age = 100;
const sentence = highlight`My dog's name is ${name} and he is ${age} years old`;
document.body.innerHTML = sentence;
console.log(sentence);
请解释下highlight这个函数的两个参数,最好能详细点es6语法
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
...values//了解一下ES6的扩展运算符,百度都有了吧