Override/Rewrite a javascript library function

主宰稳场 提交于 2020-01-01 09:58:12

问题


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?


回答1:


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();


来源:https://stackoverflow.com/questions/12099471/override-rewrite-a-javascript-library-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!