Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 855
Neha M Avatar asked Aug 23 '12 20:08

Neha M


1 Answers

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();
like image 87
Daniel Pereira Avatar answered Sep 27 '22 21:09

Daniel Pereira