为什么我在 JSHint 中得到 'Unexpected 1'?
Why am I getting 'Unexpected 1' in JSHint?
var canvas = document.createElement('canvas'),
ctx = canvas.getContext("2d"); //Create the context
//more code (width, height defined elsewhere)
ctx.beginPath();
ctx.moveTo(0.35 * width, 0);
ctx.lineTo(0.35 * width, 0.65 * height);
ctx.lineTo(1 * width, 0.65 * height); //JSHint is complaining about the 1 here
ctx.stroke();
为什么我在这里收到错误消息?
这是一个无意义的操作,乘以1没有任何作用。只需使用宽度。
发生这种情况是因为乘以 1 是多余的。
为什么不直接使用 :
ctx.lineTo(width, 0.65 * height);
据我所知 1 * 任何东西很可能会给出相同的结果
var canvas = document.createElement('canvas'),
ctx = canvas.getContext("2d"); //Create the context
//more code (width, height defined elsewhere)
ctx.beginPath();
ctx.moveTo(0.35 * width, 0);
ctx.lineTo(0.35 * width, 0.65 * height);
ctx.lineTo(1 * width, 0.65 * height); //JSHint is complaining about the 1 here
ctx.stroke();
为什么我在这里收到错误消息?
这是一个无意义的操作,乘以1没有任何作用。只需使用宽度。
发生这种情况是因为乘以 1 是多余的。
为什么不直接使用 :
ctx.lineTo(width, 0.65 * height);
据我所知 1 * 任何东西很可能会给出相同的结果