我正在尝试编写一个代码来绘制垂直线。
http://codepen.io/juyoung518/pen/BzAJwg
Chrome 在这一段上弹出错误。 未捕获的类型错误:无法读取未定义的属性“x”
function getNearestIntersections(line, arr) {
var index = arr.length - 2;
if (arr[index].x !== line.center.x) {
while (Math.sign(line.center.x - line.a.x) === Math.sign(line.center.x - arr[index].x)) {
index--;
}
} else {
while (Math.sign(line.center.y - line.a.y) === Math.sign(line.center.y - arr[index].y)) {
index--;
}
}
return [arr[arr.length - 1], arr[index]];
}
谁能告诉我问题出在哪里?
此代码笔在 IE 中根本不起作用。
最佳答案
您是否正确定义了“线”?查看您的引用资料,我明白了:
var Line = function(x1, y1, x2, y2) {
this.a = new Vec(x1, y1);
this.b = new Vec(x2, y2);
this.center = new Vec((x1 + x2) / 2, (y1 + y2) / 2);
this.dx = x2 - x1;
this.dy = y2 - y1;
};
你的代码中确实有这个(或类似的东西),不是吗?
关于javascript - Chrome 中未捕获的类型错误无法读取未定义的属性 'x',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38505847/