gpt4 book ai didi

javascript - Highcharts根据选项改变原型(prototype)函数

转载 作者:行者123 更新时间:2023-11-30 19:55:13 24 4
gpt4 key购买 nike

我想更改 Highcharts 的功能。

H.Pointer.prototype.reset

这是我的例子:

var orignalReset = H.Pointer.prototype.reset;

H.Pointer.prototype.reset = function (e) {
if(this.options.tooltip.syncronized){
return undefined;
}else{
orignalReset();
}
};

问题:通过这种方法我无法传递this 引用。分配给变量已失去与原始方法/类的连接。

最佳答案

您可以将其包装起来,如“Extending highcharts ”中所述。

我不确定 tooltip.syncronized 是什么,所以我用 tooltip.shared 做了一个例子。例如,如果工具提示是共享的,您可以包装 Pointer.reset 函数不执行任何操作,否则执行正常操作,如下所示:

(function (H) {
H.wrap(H.Pointer.prototype, 'reset', function (proceed, allowMove, delay) {
if(this.chart.options.tooltip.shared) {
console.log('shared: not doing anything.');
}
else {
console.log('not shared: normal behavior.');
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
}
});
}(Highcharts));

参见 this JSFiddle example它在两个单独的 Highcharts 上的作用。

关于javascript - Highcharts根据选项改变原型(prototype)函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54074235/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com