10

I have seen the using of:

${startX} ${startY}

in javascript. That is totally new for me. I like the idea to use it, but don't know it is proove.

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(' ');

I would write it like this:

  const pathData = [
    `M` + startX + ` ` + startY,
    ...

Does it works in jQuery also? Thx for any description-link in advance.

hamburger
  • 1,339
  • 4
  • 20
  • 41

1 Answers1

10

Template literals is an ES6 capability -- https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals. It is independent of JQuery and other libraries. The way that you have it written should work.

Max Sindwani
  • 1,267
  • 7
  • 15