mardi 29 août 2017

How to override javascript module pattern public method?

I have a module that looks like this:

var V;

V = (function() {

    var V = function() { }

    V.doSomething = function() {
        console.log('A');
    };

    return V;

})();

I would like to, after this is declared, override that doSomething method so that when I call V.doSomething() something else is printed instead of A.

I tried to simply assign a new function like so:

V.doSomething = function() { console.log('B'); }

...but that doesn't work, when I invoke V.doSomething() I get the original function invoked.

Is there a way to do that?

Aucun commentaire:

Enregistrer un commentaire