什么是javascript中的$ {variable}

ham*_*ger 6 javascript

我见过使用:

${startX} ${startY}
Run Code Online (Sandbox Code Playgroud)

在javascript中.这对我来说是全新的.我喜欢使用它的想法,但不知道它是否有用.

let cumulativePercent = 0;

function getCoordinatesForPercent(percent) {
  const x = Math.cos(2 * Math.PI * percent);
  const y = Math.sin(2 * Math.PI * percent);
  return [x, y];
}

const [startX, startY] = getCoordinatesForPercent(cumulativePercent);

const pathData = [
    `M ${startX} ${startY}`, // Move
    `A 1 1 0 ${largeArcFlag} 1 ${endX} ${endY}`, // Arc
    `L 0 0`, // Line
  ].join(' ');
Run Code Online (Sandbox Code Playgroud)

我会这样写:

  const pathData = [
    `M` + startX + ` ` + startY,
    ...
Run Code Online (Sandbox Code Playgroud)

它也适用于jQuery吗?Thx用于任何描述 - 提前链接.

Max*_*ani 8

模板文字是ES6功能 - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals.它独立于JQuery和其他库.你写它的方式应该有效.