function highlight(strings, ...values) {
let str = '';
strings.forEach((string, i) => {
str += `${string} <span contenteditable class="hl">${values[i] || ''}</span>`;
});
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语法
PHP中文网2017-04-11 12:20:57
应该是用了ES6的模板字符串和扩展运算符,我把阮一峰大师的教学列出来,
http://es6.ruanyifeng.com/#docs/string#模板字符串
http://es6.ruanyifeng.com/#docs/function#扩展运算符