覆盖/重写javascript库函数 [英] Override/Rewrite a javascript library function
问题描述
我正在使用开源JavaScript库 timeline.verite.co 这是一个时间轴库,在页面加载时效果很好.但是当我尝试在特定条件下重新绘制时间轴时,它开始发出奇怪的错误
我想修改库中的init函数.但是我不想在原始库中更改它,而是想在另一个单独的.js文件中重写/覆盖此函数,以便在调用此函数时,必须使用我修改后的函数,而不是转到原始函数. /p>
我不确定是否要使用原型/继承以及如何使用它来解决此问题?
您只需为其分配新值.这是一个示例:
obj = {
myFunction : function() {
alert('originalValue');
}
}
obj.myFunction();
obj.myFunction = function() {
alert('newValue');
}
obj.myFunction();
I am using an open source javascript library timeline.verite.co It's a timeline library which works great on page load. But when I try to repaint the timeline on certain condition, it starts giving out weird errors
I would like to modify the init function in the library. But instead of changing it in the original library itself, I would like to rewrite/override this function in another separate .js file so that when this function is called, instead of going to the original function, it must use my modified function.
I'm not sure whether to use prototype/ inheritance and how to use it to solve this problem?
You only need to assign the new value for it. Here is an example:
obj = {
myFunction : function() {
alert('originalValue');
}
}
obj.myFunction();
obj.myFunction = function() {
alert('newValue');
}
obj.myFunction();
这篇关于覆盖/重写javascript库函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!