Нужно каждый раз вызывать функцию с новой переменной namePath, а оно выдает ошибку.
Вот такой код есть:
function createNewPath(namePath,[...arr],color) {
let namePath = new Path2D()
namePath.rect([0], arr[1], arr[2], arr[3])
namePath.closePath()
ctx.fillStyle = `${color}`;
ctx.fill(namePath)
ctx.stroke(namePath)
}
вызов функции
createNewPath(contentPath,[0, height - height / 3, width, height - height / 2],"rgba(43, 41, 41, 1)");
createNewPath(redLine,[0, height - height / 3, width, height - height / 2],"rgba(43, 41, 41, 1)")
Получаю ошибку
Uncaught SyntaxError: Identifier 'namePath' has already been declared
и такую