Override/Rewrite a javascript library function

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?

Answers:

Answer

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.