如何手动删除/撤消Highcharts类原型上的包装?
我目前在Angular中的一个类中有这个,即使在组件被销毁之后,包装似乎仍然将我的方法作为一个闭包。
import * as Highcharts from 'highcharts';
export class ExampleComponent implements OnDestroy
constructor() {
function logRefresh(H) {
H.wrap(H.Tooltip.prototype, 'refresh', function(proceed, point) {
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
console.log(proceed, point);
});
}
logRefresh(Highcharts);
}
ngOnDestroy(): void {
...
}
}发布于 2021-11-22 13:46:07
wrap方法覆盖了Highcharts prototype中的原始函数,因此它是一个永久性的更改。你可以在here上检查这个方法是如何工作的。
作为解决方案,您可以将原始函数存储在某个位置,例如:
H.wrap(H.Tooltip.prototype, 'refresh', function(proceed) {
console.log('refresh');
if (!H.Tooltip.prototype.refreshOriginal) {
H.Tooltip.prototype.refreshOriginal = proceed;
}
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});并在你需要的时候恢复它。
const tooltipProto = H.Tooltip.prototype;
// restore original refresh function
tooltipProto.refresh = tooltipProto.refreshOriginal;
delete tooltipProto.refreshOriginal;现场演示: http://jsfiddle.net/BlackLabel/nfqcwhk6/
文档: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts
https://stackoverflow.com/questions/70042901
复制相似问题