使用函数参数 [jsxgraph] 删除行时出错

Error when removing line with function parameter [jsxgraph]

我有一个 JSXGraph 项目,我在 x.axis 上创建了一个点 (A) 和一条垂直于 x 轴并穿过 (A) 的线。移动 (A) 时,线应跟随点。到目前为止效果很好。
但是,在按下按钮时,我想删除线和点并释放包含线和点的变量。
这就是我的问题所在。删除 point/line 并释放变量后,update() 函数仍然调用用于定义行的函数,这会导致错误,因为函数中的变量不再存在。
知道如何解决这个问题吗?

谢谢!

Link 至 fiddle:https://jsfiddle.net/t9rcva1x/1/

const testBoard = JXG.JSXGraph.initBoard('jxgbox', { axis: true });
let testPoint = testBoard.create('point', [1, 0]);
function testfunction() {
    return testPoint.X();
}
let testLine = testBoard.create('line', [
    [testfunction, 0],
    [testfunction, 1],
]);
testBoard.removeObject(testLine);
testBoard.removeObject(testPoint);
testPoint = null;
testLine = null;
testBoard.update();

确实是对象之间的依赖关系有问题。如果一条线是由两个坐标数组创建的,例如

let testLine = testBoard.create('line', [
    [testfunction, 0],
    [testfunction, 1], 
]);

然后在内部创建两个定义线的 JSXGraph 点。现在,删除线时,JSXGraph 不会自动删除这两个内部点。解决方法是手动删除这两点:

document.getElementById('remove').addEventListener('click',()=>{
    testBoard.removeObject([
        testLine.point1, testLine.point2, testLine, testPoint
    ]);
});

https://jsfiddle.net/61ny8hm7/1/

最良好的祝愿, 阿尔弗雷德