我见过使用:
${startX} ${startY}
在 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(' ');
我会这样写:
const pathData = [
`M` + startX + ` ` + startY,
...
它也适用于 jQuery 吗?感谢提前提供任何描述链接。
模板文字是 ES6 的一项功能——https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals。它独立于 JQuery 和其他库。您编写的方式应该有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)