javascript - JS 请解释下这两个参数啥意思function highlight(strings, ...values)。
PHP中文网
PHP中文网 2017-04-11 12:18:57
0
2
645
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中文网
PHP中文网

认证0级讲师

reply all(2)
Ty80

应该是用了ES6的模板字符串扩展运算符,我把阮一峰大师的教学列出来,

http://es6.ruanyifeng.com/#docs/string#模板字符串

http://es6.ruanyifeng.com/#docs/function#扩展运算符




Peter_Zhu

...values//了解一下ES6的扩展运算符,百度都有了吧

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template